Sandip Ransing
2009-Jun-03 07:19 UTC
Anyone knows how to do left join as well as inner join in same query.
Hello All, Is rails supporting left and inner joins in same query ?? I dont wanted to do it using find_by_sql. I have model having belongs_to and has_one associations. I wanted to something like...... Model.find ( :all, left join on belongs_to model and inner join on has_one model, :select =>. "some attributes from all models" ) Thanks for help ! Sandip -- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Timberlake
2009-Jun-03 07:27 UTC
Re: Anyone knows how to do left join as well as inner join in same query.
On Wed, Jun 3, 2009 at 9:19 AM, Sandip Ransing <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello All, > > Is rails supporting left and inner joins in same query ?? > I dont wanted to do it using find_by_sql. > > I have model having belongs_to and has_one associations. > > I wanted to something like...... > > Model.find ( :all, left join on belongs_to model and inner join on has_one > model, :select =>. "some attributes from all models" ) > > Thanks for help ! > > Sandip > -- > Ruby on Rails Developer > http://sandip.sosblog.com > http://funonrails.wordpress.com > www.joshsoftware.com >Check the docs at http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002208 use :joins to include join SQL syntax :joins => ''inner join x outer join y'' Andrew Timberlake http://ramblingsonrails.com http://MyMvelope.com - The SIMPLE way to manage your savings
Sandip Ransing
2009-Jun-03 09:37 UTC
Re: Anyone knows how to do left join as well as inner join in same query.
Thanks ! On Wed, Jun 3, 2009 at 12:57 PM, Andrew Timberlake < andrew-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> wrote:> > On Wed, Jun 3, 2009 at 9:19 AM, Sandip Ransing <san2821-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hello All, > > > > Is rails supporting left and inner joins in same query ?? > > I dont wanted to do it using find_by_sql. > > > > I have model having belongs_to and has_one associations. > > > > I wanted to something like...... > > > > Model.find ( :all, left join on belongs_to model and inner join on > has_one > > model, :select =>. "some attributes from all models" ) > > > > Thanks for help ! > > > > Sandip > > -- > > Ruby on Rails Developer > > http://sandip.sosblog.com > > http://funonrails.wordpress.com > > www.joshsoftware.com > > > > Check the docs at > http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002208 > > use :joins to include join SQL syntax > :joins => ''inner join x outer join y'' > > Andrew Timberlake > http://ramblingsonrails.com > > http://MyMvelope.com - The SIMPLE way to manage your savings > > > >-- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---