HABTM最佳实践

问题描述

| 我有2个主要实体,UserProfile和Property。基本上,UserProfile需要维护3个不同的属性列表(注意,每种列表类型将具有其他属性) 有人认为以下设计有什么问题吗?
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
我考虑的另一种方法是对Property实体使用多态, 但不确定哪种方式更适合“导轨方式”     

解决方法

        HABTM稍有过时,已由has_many:through代替。此外,请查看有关多态关联的Railscast。 Ryan Bates很好地解释了这一点。     ,        当然,多态似乎是正确的想法。它正盯着你。但是,如果您做得太过分,我想警告您远离ѭ1宝石。 Rails 3版本已经过时,有故障,尚未接近成熟,这会使您的开发环境变得异常沉重(每个请求都需要额外的4-6秒来加载)。 进一步阅读多态性,例如: http://quickleft.com/blog/advanced-activerecord-recipes-doubly-polymorphic-join-models     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...