一个简单的has_and_belongs_to_many
协会:在HABTM连接表上需要两个索引?
Person has_and_belongs_to_many :products
Product has_and_belongs_to_many :persons
是以下指标以获得最佳性能很有帮助的两个?
add_index :person_products, [:person_id, :product_id]
add_index :person_products, [:product_id, :person_id]
我的理解是,如果查询是通过'product_id'然后'person_id'进行的,它不会使用上面两个列中的索引。 – sscirrus 2013-03-04 20:47:04