Hi, I did the following to compare two tables, products and orders using LEFT OUTER JOIN. It came out fine.
However, I am not sure how to do the similar join if the products are an array. For example, there is another table called brands having the relationships - brand has_many:products and products belongs_to:brand. @brands = brand.find(params[:id])picks up particular brand and all the products from that brand.
On the view, I would like to display list of products from one brand and do LEFT OUTER JOIN with orders table. I would truly appreciate the advise on how to modify the following to accomplish this task or at least guide me to the right direction.
Table products id name brand_id
Table orders id product_id customer_name
product has_many: orders order belongs_to: product
Def list @products = Product.find(:all) @orders = Order.find(:all) @compares = Product.connection.select_all("SELECT products.id AS prod,products.name AS name, orders.product_id AS ord FROM products LEFT OUTER JOIN orders ON products.id = orders.product_id") end