【发布时间】:2010-10-26 01:24:02
【问题描述】:
我正在尝试了解 RoR 中的 has_one 关系。
假设我有两个模型 - Person 和 Cell:
class Person < ActiveRecord::Base
has_one :cell
end
class Cell < ActiveRecord::Base
belongs_to :person
end
我可以在Cell 模型中只使用has_one :person 而不是belongs_to :person 吗?
不是一样的吗?
【问题讨论】:
-
上面的代码不正确,应该是
has_one :cell和belongs_to :person,冒号和后面的单词之间应该不有空格。
标签: ruby-on-rails ruby has-one