[ruby-it] ActiveRecord come trovare i record prima e dopo

David Welton davidnwelton a gmail.com
Mar 16 Mar 2010 19:44:17 CET


Forse qualcosa del genere:

    # Most voted tweets
    @votedtweets = Status.find(:all, :include => ['tuser', 'votes'],
:joins => "join (select status_id, count(distinct user_id) as cnt from
votes, statuses where votes.status_id = statuses.id and
statuses.tcreated_at > '#{1.week.ago}' group by status_id,
statuses.tcreated_at order by cnt desc, tcreated_at desc limit 5) as
mystats on mystats.status_id = statuses.id", :order => 'mystats.cnt
desc, tcreated_at desc')

Funziona bene su postgres.

-- 
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/


More information about the Ml mailing list