2013-03-14 54 views
0

我努力讓這些關係發揮作用。 我有以下類FlowContainerMongoid multiple has_one relations

class FlowContainer 
    include Mongoid::Document 
    has_one :production_flow, class_name: Flow 
    has_one :test_flow, class_name: Flow 
    has_one :design_flow, class_name: Flow 
end 

正如你所看到的,我希望它有3個具體的流程。我設置在流動的關係是這樣的:

class Flow 
    include Mongoid::Document 
    belongs_to :flow_container 
end 

我不認爲這是一些特別的東西,應該在我看來工作,但是當我嘗試將流量分配到上面我提到的具體流向的一個因爲我覺得這應該工作

NoMethodError: undefined method `sub' for Flow:Class

我也可以去繼承設置一個通用的流程和3個個子類,但就目前而言,我並不贊成該解決方案:收到此錯誤信息。 如果有人能就此事分享他的意見,我將不勝感激。

+0

您可以發佈您的控制器代碼\ – 2013-03-14 10:38:02

+0

設置'inverse_of'關係 – apneadiving 2013-03-14 10:46:37

+0

不應類名是一個字符串? 「流量」而不是恆定的流量? – fmendez 2013-03-14 10:48:44

回答

3

class_name必須通過爲string,試試這個:

has_one :test_flow, class_name: "Flow"