I have a table called “order” which has many “order_items” , each “order_items” is belongs_to “order” and “product”. In the db, I have one record in order. the record is like this:
orders table: id = 1 name= customer
and the order_items table is like this:
id=1 product_id=233 order_id =1
id=2 product_id=454 order_id =1
I have the @orders obj, how can I use the orders and find out the order items and products information?
You should be able to use:
and
Check out the following page:
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
..pay particular attention to the first introductory section.