我的应用程序有5种核心模型。我正在尝试找出关联模型的最佳方法。我应该建立多少张表以及哪种类型的表?
以下是我要包括的关联及其各自的模型:
用户
有很多板
有很多列表
有很多卡
有很多评论
董事会
有很多用户
有很多列表
有很多卡
清单
属于登机
有很多卡
卡
属于板
属于列表
有很多评论
注释
属于卡
属于用户
class User < ActiveRecord::Base
has_and_belongs_to_many :boards
has_many :lists, as: listable
has_many :cards, as: cardable
has_may :comments, as: commentable
end
class Board < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :lists, as: listable
has_many :cards, as: cardable
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
class List < ActiveRecord::Base
belongs_to :listable, :polymorphic => true
has_many :cards, as: cardable
end
class Card < ActiveRecord::Base
belongs_to :cardable, :polymorphic => true
has_many :comments, as:commentable
end
要建立HABTM关系,您必须创建一个名为“ users_boards”的表
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句