views:

38

answers:

1

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?

+1  A: 

You should be able to use:

@orders.order_items

and

@orders.product

Check out the following page:

http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

..pay particular attention to the first introductory section.

fd