Hi
I have the models User and Payment. The relation between them
user has_many payments
payment belongs_to user
payments table has a field paid_date. Now for finding out the last
paid_date for a particular user I did like
class payment < ActiveRecord::Base
named_scope :last_payment_date, :select => ‘MAX(date_paid) as
date_paid’
end
Then @user = User.find(id)
@user.payments.last_payment_date
I get the correct answer. But actually is this correct? Because
sql generated is
SELECT MAX(date_paid) as date_paid FROM payments
WHERE
(payments
.user_id = 8) AND (payments
.user_id = 8)
I would like to know why (`payments`.user_id = 8) appears twice
Thanks