Beta Beta
2008-Jul-31 23:42 UTC
is it possible for table intersection reference same table
Hi, Hopefully this is not confusing. ---- WHAT I need is this below ---------------- SQL Statement Select * from table_mains left join table_a where table_a.id = table_mains.table_a_id left join table_b where table_b.id = table_mains.table_b_id left join photo pa where pa.id = table_mains.photo_a_id left join photo pb where pb.id = table_mains.photo_b_id ------------------------------------------------------- What I have try table_mains = TableMain.find(:all,:include=>[:table_a, :table_b, :photo]) It only return left join from table_b but not table_a --------Here are the tables-------------------- table_mains - table_a_id (column) - photo_a_id (column) - table_b_id (column) - photo_b_id (column) photos table_a table_b -------------------------------------------------------------------- class TableMain < ActiveRecord::Base belongs_to :table_a,:foreign_key => "table_a_id" belongs_to :table_b,:foreign_key => "table_b_id" belongs_to :photo,:foreign_key => "photo_a_id" belongs_to :photo,:foreign_key => "photo_b_id" end ----------------------- class TableA < ActiveRecord::Base has_one :table_main end ----------------------- class TableB < ActiveRecord::Base has_one :table_main end ------------------- class Photo < ActiveRecord::Base has_one :table_main end -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Tim Gossett
2008-Aug-01 14:15 UTC
Fwd: [Rails] is it possible for table intersection reference same table
On Thu, Jul 31, 2008 at 7:42 PM, Beta Beta <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > ---- WHAT I need is this below ---------------- > SQL Statement > Select * from table_mains > left join table_a where table_a.id = table_mains.table_a_id > left join table_b where table_b.id = table_mains.table_b_id > left join photo pa where pa.id = table_mains.photo_a_id > left join photo pb where pb.id = table_mains.photo_b_id > ------------------------------------------------------- > What I have try > table_mains = TableMain.find(:all,:include=>[:table_a, :table_b, > :photo]) > > It only return left join from table_b but not table_a >try this: table_mains = TableMain.find(:all, :include=> [:table_a, :table_b, :photo], :joins => "left join table_a where table_a.id table_mains.table_a_id left join table_b where table_b.id table_mains.table_b_id left join photo pa where pa.id table_mains.photo_a_id left join photo pb where pb.id table_mains.photo_b_id") -- Tim Gossett --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Beta Beta
2008-Aug-01 18:04 UTC
Re: is it possible for table intersection reference same tab
Just in case, if any one else interested. I resolved the problem by using class_name in has_many -- 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-/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 -~----------~----~----~----~------~----~------~--~---