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

Just in case, if any one else interested.

I resolved the problem by using class_name in has_many

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs