如何在fixture中指定多态关联

时间:2011-08-09 04:15:43

标签: ruby-on-rails-3 polymorphic-associations fixtures

我有这个装置:

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

资源定义如下:

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

用户定义如下:

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

当我运行测试时,我收到一条错误,表示未在表中定义列“所有者”。我做错了什么?

1 个答案:

答案 0 :(得分:2)

灯具应该有owner_id和owner_type。例如:owner_id为1,owner_type为“用户”