Factory-girl: 'association'命名的列与工厂方法命名的'association'重叠

3

我有以下的工厂定义。

Factory.define :status do |f|

end 

Factory.define :my_status , :parent => :status do |f|
  f.association 'something_here'
  f.alias 'something_here'
  f.name  'something_here'
end 

我知道有一个工厂定义的“关联”方法,类似于: f.association :group, :factory => :group 但实际上我有一个名为association的列。那么该如何给我的列赋值呢?
更新: Maletor的帖子后,我想到了一种解决方法-谢谢Maletor 我在我的状态模型中添加了这个。
  alias_attribute :assoc, :association 

现在我可以做到:

Factory.define :my_status , :parent => :status do |f|
  f.assoc 'somthing_here'
  f.alias 'somthing_here'
  f.name  'somthing_here'
end

运作良好 :)

1个回答

2
你可以在 f.after_create 中分配它。虽然不太优雅,但这也是一种方法。重命名列也许也不是一个坏主意。

1
这是一个好方法,问题在于我正在预加载这些工厂,而在我的情况下它不起作用。重命名表列不是一个选项,但这引出了在模型中为此列创建别名的想法。我已将其添加到上面的描述中。 - VelLes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接