I have this scenario:
class Order < ActiveRecord::Base
has_and_belongs_to_many :products
end
class Product < ActiveRecord::Base
has_and_belongs_to_many :orders
end
class CreateJoinTableOrdersProducts < ActiveRecord::Migration
def change
create_join_table :orders, :products do |t|
t.index [:order_id, :product_id]
t.index [:product_id, :order_id]
t.decimal :price, precision: 8, scale: 2
t.integer :quantity, default: 1
end
end
end
Now, I need to add some records using the command line:
This works fine:
Order.first.products << Product.first
But, I need to add some more fields, like: price
, quantity
...
How can I do this?