Depends on how you layout your models.  Things like "left join
my_other_table on my_other_table.forein_key_id = my_table.id"  are
taken care of by AR if you set up the associations properly.  You
could then do a Model.count(:joins=>..., :conditions=>....)

On Jun 4, 12:38 am, Fernando Perez <[email protected]>
wrote:
> Roland Mai wrote:
> > here you go:
>
> > select count(*)
> > from (select distinct field_id from my_table
> >       left join my_other_table on my_other_table.forein_key_id =
> > my_table.id
> >       where field_id < 5) as a
> > left join some_other_table  on a.other_id = some_other_table.id
> > where some_other_table.created_at < getdate()
>
> Hi, yahoo search brought me to this old topic, but I am running into the
> same problem. So is find_by_sql the only way to perform joins on
> inner-selects?
> --
> Posted viahttp://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