I tend to craft inner selects separately and then include them manually in a 
crafted join statement. 

Eg Something like:

Post.join("left join ( #{Comment.select('post_id, max(created_at) as 
created_at').group('post_id').to_sql}) as c on 
c.post_id=#{Post.table_name}.id).order('ts desc')

Which is easy to turn into a scope on post

Sent from my iPhone

On 22/02/2013, at 12:55 AM, Krasimir Angelov <[email protected]> wrote:

> Query should be something like this 
> https://gist.github.com/anonymous/5004860. You can try translate it to arel 
> or just use find_by_sql.
> 
> 
> On Thursday, February 21, 2013 12:12:37 PM UTC+2, Alex Bayley wrote:
>> 
>> On 21/02/13 9:10 PM, Steven Ringo wrote: 
>> > What about using Post.order(:created_at) and then working it from there? 
>> > 
>> > Also you get the database to do the sorting for you, which is way more 
>> > efficient than having Ruby do it :-) 
>> 
>> Because it doesn't do what we want, which is to show the most recently 
>> active post -- including comments on that post. 
>> 
>> A. 
>> 
>> 
>> -- 
>> Alex "Skud" Bayley 
>> [email protected] 
>> http://growstuff.org/ 
>> For personal stuff, please use [email protected]
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby or Rails Oceania" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/rails-oceania?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rails-oceania?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to