【发布时间】:2010-09-15 02:45:51
【问题描述】:
例如,在
class Student < ActiveRecord::Base
has_many :awards
end
class Awards < ActiveRecord::Base
belongs_to :student
end
上面应该是正确的用法,但是如果我们使用呢
class Student < ActiveRecord::Base
has_many :awards
end
class Awards < ActiveRecord::Base
has_one :student
end
上面不是也可以将student.awards 作为一个Award 对象数组,将award.student 作为一个Student 对象,它是该奖项的获得者,所以工作方式与帖子顶部的方法相同?
【问题讨论】:
-
参见:[维基百科上的基数](en.wikipedia.org/wiki/Cardinality_(data_modeling%29)
标签: ruby-on-rails activerecord belongs-to has-one