[英]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.