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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.