Last Updated: 2021-05-15
I had the following code:
@law_cases = LawCase.select(:slug, :name).include(:law_disciplines)
In the controller I had the following:
The output of this controller code turned out to always be unexpectedly empty (i.e. containing 0 names).
This turned out to be due to the law of
:id column in the select for the
LawCase. Without that
id column, the joins broke down. Once I added
:id back into the
select statement, everything worked again.
Always include ids in your select statement if you plan on joining. (In fact, it's probably a good idea to grab them just in case in all situations that aren't performance bottlenecks.)