[英]how to add a new association to library model
I am using merit library in rails. 我在Rails中使用绩效库。 And hope to add an association in Merit::Score::Point so that it has a has_one association with another model call ScoreWorkflow.
并希望在Merit :: Score :: Point中添加一个关联,以便它与另一个调用ScoreWorkflow的模型具有has_one关联。
Below is my code. 下面是我的代码。 In this code, I hope to add an association so that I can add a has_one to the library model.
在这段代码中,我希望添加一个关联,以便可以将has_one添加到库模型。 However it does not work.
但是,它不起作用。 Is there anything that like this that I can put some function/assoication to a library model.
有什么类似的事情我可以将一些函数/关联添加到库模型中。 Thanks.
谢谢。
module Merit
module Score
class Point < Point
has_one :score_workflow
end
end
end
class ScoreWorkflow
belongs_to :point
end
If you want it the other way around... 如果您想反过来...
module Merit
module Score
class Point < Point
belongs_to :score_workflow
end
end
end
... and... ...和...
class ScoreWorkflow
has_one :point
end
Sometimes you must specify the class names: 有时您必须指定类名称:
module Merit
module Score
class Point < Point
has_one :score_workflow, :class_name => "ScoreWorkflow"
end
end
end
class ScoreWorkflow
belongs_to :point, :class_name => "Merit::Score::Point"
end
Also make sure to check your foreign keys if you use ActiveRecord, so they match the conventions. 如果使用ActiveRecord,还请确保检查您的外键,以便它们符合约定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.