我有两个型号:如何使协会工作
class Group < ActiveRecord::Base
belongs_to :sites
end
class Site < ActiveRecord::Base
has_many :groups
end
我可以得到属于网站的所有组:
Site.find(1).groups
但我不能让网站属于某一组:
$ Group.find(1)
#<Group id:1 ...., site_id: "1">
$ Group.find(1).sites
nil
为什么?
它不应该是'belongs_t o:网站? –
是的,谢谢。你可以创建答案,我会结束答案? – demas
勾选Atzoya。没有必要有相同内容的答案,我会活下来没有收到15分。 ;) –