Answer the question
In order to leave comments, you need to log in
ActiveRecord relationship across multiple fields?
How to properly configure ActiveRecord to write the query correctly, there are 2 tables Table1 ( id1, id2) and table Table2 ( id1, id2, enabled ).
You want the output to be like this:
SELECT table1.id1, table1.id2 FROM table2 LEFT JOIN table1 on table1.id1 = table2.id1 and table1.id2 = table2.id2
WHERE table2.enabled = true
Answer the question
In order to leave comments, you need to log in
More or less like this:
Table2Model.
joins("LEFT JOIN table1 on table1.id1 = table2.id1 and table1.id2 = table2.id2").
# и т.д.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question