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...@gmail.com> wrote: > On Jul 20, 6:45 pm, Ritesh <ragra...@gmail.com> 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.