开发者

How to specify a polymorphic association in a fixture

开发者 https://www.devze.com 2023-03-26 15:56 出处:网络
I have this fixture: resource: name: my resource owner: user_1 (User) Resource is defined like this: class Resource < ActiveRecord::Base

I have this fixture:

resource:
  name: my resource
  owner: user_1 (User)

Resource is defined like this:

class Resource < ActiveRecord::Base
  belongs_to :owner, :polymorphic => true

User is defined like this:

class User < ActiveRecord::Base
  has_many :resources, :as => :owner

When I run the test I get an error tha开发者_开发问答t the column 'owner' is not defined in the table. What am I doing wrong?


The fixture should have owner_id and owner_type. For example: owner_id as 1 and owner_type as "User"

0

精彩评论

暂无评论...
验证码 换一张
取 消