Strange ActiveRecord::AssociationTypeMismatch

后端 未结 5 474
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:42

    Rather than disable class caching, which can be aggravating while in development, the problem might disappear if you get your object fresh before using it. In my case I was loading an object from an association:

    desired_object = foo.bar
    

    Finding the item instead removed the problem and didn't require caching classes.

    desired_object = Bar.find(foo.bar_id)
    

    I know it isn't ideal, but perhaps this will help someone find out just why it is happening at all.

提交回复
热议问题