I have 3 separate tables A
, B
and C
. Table A
and table B
are two separate tables that have very similar attrs, in fact table B
is just an extension of table A
but it had to be separated due to business requirements. Both tables has_many
relation to table C
. Below is a better representation of the relationship between the three table
class A < ActiveRecord::Base
has_many :c, dependent: :destroy
end
class B < ActiveRecord::Base
has_many :c, dependent: :destroy
end
class C < ActiveRecord::Base
belongs_to :a, optional: true
belongs to :b, optional:true
end
So the problem comes when I'm trying querying information from table C
and need the information from table A
and B
as well. If I do C.where(user_id: 5).joins(:a)
, it only returns me the record that can join with A
. Likewise for table B
. But if I do C.where(user_id: 5).joins(:a, :b)
I get a []
response. FWIW, the information I need from A
and B
are have the same column names when accessing them. Still very new to rails, any help is appreciated.