Reputation: 151
i have this :
Order.find(19).order_items
=> #<ActiveRecord::Associations::CollectionProxy []>
how can i add this object "order_item" to "Order"?
order_item = OderItem.find(2)
Upvotes: 0
Views: 296
Reputation: 4093
There is your answer :
Order.find(19).order_items << OrderItem.find(2)
After reading some comments, let me improve my answer by adding this link : http://guides.rubyonrails.org/association_basics.html#has-many-association-reference You can look at the 4.3.1.2 collection<<(object, ...) point
Upvotes: 2