1
我可以创建一个给定的person
这样的statistic
记录:控制器代码来创建有两个belongs_to的关系
@person = Person.find(person.id)
@statistic = @person.statistics.build(:value => @value, :updated => @updated)
有person
和statistic
之间的one-to-many
(has_many
/belongs_to
)的关系。
上述工作正常。
不过,我也希望statistic
属于一个race
太(赛事在跑步/驱动座圈),即我已经改变了我statistic
模型有两个belongs_to
S:
belongs_to :person # just had this before
belongs_to :race # this is new
是上述正确或者我需要在我的模型中以某种方式使用through
?如果是这样,怎么样?
如何更改我的控制器代码以进行此更改?
非常感谢。
谢谢埃拉德: )。 – ale