Hi, I am wondering what''s the best way to achieve this query: select * from A left outer join B where B.a_id = A.id and B.some_other_field = random_value where A.id = 12 Notice this is different from select * from A left outer join B on B.a_id = A.id where A.id = 12 and B.some_other_field = random_value While the second query can be easily achieved using includes, I didn''t find any good way to issue first query I will appreciate any help. Regards, -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 20, 6:45 pm, Ritesh <ragra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I am wondering what''s the best way to achieve this query: > select * from A left outer join B where B.a_id = A.id and > B.some_other_field = random_value where A.id = 12 > > Notice this is different from select * from A left outer join B on > B.a_id = A.id where A.id = 12 and B.some_other_field = random_value > > While the second query can be easily achieved using includes, I didn''t > find any good way to issue first query >I think you just have to compose the join yourself - A.joins("left outer join B on ...).where(''A.id = ?'', 12) Fred> I will appreciate any help. > > Regards,-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This seems to be a common problem. I am surprised that there is not rails way to do this. Ritesh On Jul 21, 1:58 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 20, 6:45 pm, Ritesh <ragra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I am wondering what''s the best way to achieve this query: > > select * from A left outer join B where B.a_id = A.id and > > B.some_other_field = random_value where A.id = 12 > > > Notice this is different from select * from A left outer join B on > > B.a_id = A.id where A.id = 12 and B.some_other_field = random_value > > > While the second query can be easily achieved using includes, I didn''t > > find any good way to issue first query > > I think you just have to compose the join yourself - A.joins("left > outer join B on ...).where(''A.id = ?'', 12) > > Fred > > > > > > > > > I will appreciate any help. > > > Regards,-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.