I can see that my hopes of someone just telling me the answer were a bit 
optimistic. :)

Ok, after a bit of help from a friend i have the sql - it works on the 
basis of doing a left join with sign_ins (with the conditions on the 
join) and then getting back the rows where we have nothing on the right 
hand side (ie no matching sign ins).

  select * from users left join sign_ins on (users.id = sign_ins.user_id 
and sign_ins.created_at > '2009-08-12 00:00:00') where sign_ins.id is 
null;

next step, turn this into a named scope.  I can manage this, and it 
seems to work, but is a bit ugly.  Is there a nicer way?  eg avoiding 
the string evaluation stuff for the date.

  named_scope :no_login_for_last_two_months, lambda { { :joins => "left 
join sign_ins on (users.id = sign_ins.user_id and sign_ins.created_at >= 
'#{2.months.ago.to_s(:db)}')", :conditions => "sign_ins.id is null"} }
-- 
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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to