All products have an order_id, but some orders are open and some are
closed. I need a way to find all products that belong to open orders
(the field status = 1 in the orders table).
Here’s the general idea of what I’m trying to do:
@products = Product.find(:all, :conditions=>[“order.status = ?”, “1”])
order.status obviously isn’t working because it’s a reference to a
different table. I’m having a hard time figuring out how to get this to
do what I need it to do.
Thanks!!
Patrick wrote:
All products have an order_id, but some orders are open and some are
closed. I need a way to find all products that belong to open orders
(the field status = 1 in the orders table).
Here’s the general idea of what I’m trying to do:
@products = Product.find(:all, :conditions=>[“order.status = ?”, “1”])
order.status obviously isn’t working because it’s a reference to a
different table. I’m having a hard time figuring out how to get this to
do what I need it to do.
Thanks!!
Add a joins clause to your find, eg :joins => 'INNER JOIN orders on
etc…"
Fred