I have 3 models.
Model A belongs to model B and model B has many model C
by using through I can set in model A class has_many :c,through: :b
Now whenever I call a_instance.cs It would JOIN with table B unnecessarily What I want is direct association of A & C using b_id in both A & C class.
So how can I write a has_one/has_many rails association without through clause when both Source and Destination entities has same foreign_key of 3rd entity? (b_id for this example)
class C
belongs_to :b #b_id column is there in DB
end
class B
has_many :cs
end
class A
belongs_to :b #b_id column is there in DB
has_many :cs , through: :b #This is the association in Question
#WHAT I WANT TO DO. So something in place of primary_key which would fetch C class directly.
has_many :cs ,class_name: 'C',foreign_key: 'b_id',primary_key: 'b_id'
end