In Ruby on rails, our model includes orders and payments. There's 1-many relationship between order and payments. In the orders model we specify: *has_many :payments, :as => :payable* And a payment record has payable_id that is set to order.id.
In a report, I want to select all payments that belong to orders of a given type. Using: payments = Payment.find(:all, :conditions => conditions) and adding 'payable.type="a" ' to the conditions doesn't work. It seems that ActiveRecord doesn't develop this into a correct join statement (payable_id=order.id and orders.type='a'). I cannot use explicit SQL here, as the condition contains other things that are inserted there earlier in the code. Thanks, Raffi Lipkin