1
目前,我有两个类别Theme
和Offer
通过包含theme_id
和offer_id
的连接表themes_offers
映射。Rails ActiveRecord:如何为has_and_belongs_to_many关系连接表提供自定义订单?
我需要为每个主题提供自定义的优惠顺序。
所以目前的想法,我已经是在表上添加一列,并创建映射到表的新ActiveRecord类:
class AddOrderToThemesOffers < ActiveRecord::Migration[5.0]
def up
add_column :themes_offers, :order, :integer
# mark order for each existing orders
add_index :themes_offers, [:theme_id, :order], unique: true, name: 'index_offer_order_on_theme'
end
def down
remove_index :themes_offers, 'index_offer_order_on_theme'
remove_column :themes_offers, :order, :integer
end
end
会不会有更好的办法?我在这个解决方案中遇到的问题是,实现activeadmin接口来处理订单将会很困难。