Strange ActiveRecord::AssociationTypeMismatch

后端 未结 5 471
Happy的楠姐
Happy的楠姐 2021-02-01 16:10

I am getting a very strange error when running a spec:

Failure/Error: entity = Factory.create(:entity, :name => \"Test Entity\", :creator => user)
 ActiveR         


        
5条回答
  •  清酒与你
    2021-02-01 16:25

    The issue for me was in my factory definition where I was using additional factories to populate id fields. I accidentally referred to an attribute that didn't exist on the table (account, instead of account_id). See example below.

    factory Omni::CustomerAccount do
      sequence(:display_name) {|n| "test #{n}"}
      customer_id :customer  # this is correct
      account :account  # wrong - this should say account_id :account
    end
    

    Hope this helps someone.

提交回复
热议问题