例如,在在Rails中,使用「has_many with belongs_to」和「has_many with has_one」有什麼區別?
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.student
作爲獎項獲得者的學生對象,因此其工作方式與帖子頂部的方法相同?
See:[Cardinality on wikipedia](http://en.wikipedia.org/wiki/Cardinality_(data_modeling%29) – NullUserException 2010-09-15 02:51:50