[英]RoR: Model Associations
(对不起我的英文)如果我有3个模特,:电影:演员:连接,我怎么能成为id协会? 连接模型有一个movie_id:整数和一个actor_id:整数,我想在演员和电影之间建立联系。
干得好。
在电影模型中:
class Movie < ActiveRecord::Base
has_many :connects
has_many :actors, :through => :connects
end
在演员模型中:
class Actor < ActiveRecord::Base
has_many :connects
has_many :movies, :through => :connects
end
在Connect模型中:
class Connect < ActiveRecord::Base
belongs_to :movie
belongs_to :actor
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.