現在のところ、私はとOffer
という2つのクラスを、の結合テーブルによってマップし、theme_id
とoffer_id
を含んでいます。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インターフェイスを実装するのが難しいということです。