2012-11-01 26 views
0

我的應用程序使用polymorhpic關係,像這樣:在我的has_many當使用在軌多態關係,我不能使用下劃線屬性名(導軌)

class Child < ActiveRecord:Base 
    belongs_to :child_owner, polymorphic: true 
end 

class Parent < ActiveRecord:Base 
    has_many :children, as: :child_owner, dependent: :destroy 
end 

這種設置工作正常。但是,當我將屬性名稱:children更改爲像:kids_of_parent這樣的多字變量時,我得到一個未初始化的常量異常(對於Parent :: KidsOfParent)。就我而言,多字變量會更具描述性。我究竟做錯了什麼?至少有人能證實這種行爲?

感謝,

克里斯

使用Rails 3.2.8與1.9.3紅寶石

回答

0

我想使用的時候非常規的名字,這樣你應該指定一個類:

has_many :kids_of_parent, as: :child_owner, class_name: "Child", dependent: :destroy 
+0

啊,這很有道理。簡直不敢相信我自己說這是下劃線的事情。今天的計算機太長了。 – cgat