I have been trying to figure out how to fix a particular joins query to pull back everything from the query in the joined tables, but for some reason results only come back from either one table or the other. Code: p = Page.find(1, :joins => :page_translations, :conditions => [''page_translations.page_id = ?'', 1]) The above will back everything from the pages table but nothing from the page_translations table. Code: p = PageTranslation.find(1, :joins => :page, :conditions => [''page_translations.page_id = ?'', 1]) The above will back everything from the page_translations table but nothing from the pages table. I am needing to pull everything back from both tables. Thanks in advance for all the help! -- Posted via http://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 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 Oct 11, 3:03 am, Dennis Monsewicz <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have been trying to figure out how to fix a particular joins query to > pull back everything from the query in the joined tables, but for some > reason results only come back from either one table or the other. > > Code: > p = Page.find(1, :joins => :page_translations, :conditions => > [''page_translations.page_id = ?'', 1]) > > The above will back everything from the pages table but nothing from the > page_translations table. > > Code: > p = PageTranslation.find(1, :joins => :page, :conditions => > [''page_translations.page_id = ?'', 1]) > > The above will back everything from the page_translations table but > nothing from the pages table. > > I am needing to pull everything back from both tables. > > Thanks in advance for all the help!AR defaults the select clause to pages.* (in the first case) but you can override it if you want. beware about having multiple columns with the same name selected (eg id) as they will stomp on each other Fred> -- > 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 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.
Frederick Cheung wrote:> AR defaults the select clause to pages.* (in the first case) but you > can override it if you want. beware about having multiple columns with > the same name selected (eg id) as they will stomp on each other > > Fred@Fred, can you give me an example of doing this? -- Posted via http://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 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 Oct 11, 2:54 pm, Dennis Monsewicz <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: > > AR defaults the select clause to pages.* (in the first case) but you > > can override it if you want. beware about having multiple columns with > > the same name selected (eg id) as they will stomp on each other > > > Fred > > @Fred, can you give me an example of doing this?:select => ''pages.*, page_translations.some_column'' Fred> -- > 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 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.