Correct me if I'm wrong, but can't that query be rewritten as follows:
select event_id, user_id, max(invite_time) as last_invite_time
from invitations
where event_id = @event_id
group by event_id, user_id
Basically you want to get distinct event_id and user_id and the latest
invite_time? No need to join to itself.
In that case, you could go ahead and do it like this in ActiveRecord:
Invitation.select("event_id, user_id, max(invite_time) as
last_invite_time").group("event_id,
user_id").where(:event_id => @event_id)
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.