我有2个主要实体UserProfile和Property。基本上,用户配置需要维持3名不同的属性列表(注意,每个列表类型将有额外属性)HABTM最佳实践
有谁看到什么毛病以下设计这样做:
class UserProfile < ActiveRecord::Base
has_many :shortlists
has_many :booklists
has_many :proplists
end
class Shortlist < ActiveRecord::Base
has_and_belongs_to_many :properties
end
class Booklist < ActiveRecord::Base
has_and_belongs_to_many :properties
end
class Proplist < ActiveRecord::Base
has_and_belongs_to_many :properties
end
class Property < ActiveRecord::Base
has_and_belongs_to_many :shortlists
has_and_belongs_to_many :booklists
has_and_belongs_to_many :proplists
end
另一种方法我正在考虑的是使用多态性的财产实体, ,但不知道哪种方式会更'轨道'
'导轨方式'的关键之一是避免重复自己。您应该使用多态性来将这些列表合并为List类的后代。 – Mario 2011-05-27 15:36:55
请注意,has_and_belongs_to_many将被弃用,并用has_many,:through – apneadiving 2011-05-27 15:37:55