What is the most elegant way to save new one-many associations?
order = Order.new(:name => “My Order”)
order.line_items << LineItem.new(:product_id => 1, :quantity => 2)
order.line_items << LineItem.new(:product_id => 2, :quantity => 5)
The above - which is by far the most elegant way of putting it - doesn’t
work for me - the line_items don’t get saved. Presumably because the
order does not have an id yet, so they’re not linked up.
What is the best way to deal with such one-many associations when
creating new ones, other than first saving the order, then adding the
line_items and saving the order again?