2013-03-14 58 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"