2011-08-25 25 views
3

我有以下工廠定義。工廠女孩:名爲'association'的工廠方法命名列重疊'

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:組:廠=>:組 但我確實有一個名爲列關聯。什麼是將值分配給我的列的方式?

更新: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 

工作正常:)

回答

2

你可以分配它在f.after_create。雖然沒有那麼優雅。重命名該列也不是一個壞主意。

+1

這是一個好方法,問題是我預加載了這些工廠,並且在我的情況下不起作用。重命名錶列不是一個選項,但是這是通過在此列的模型中創建別名的方式。我在上面的描述中添加了這一點 – VelLes