I think has_many :through could be improved to use a WHERE instead of INNER JOIN, when possible
I was just wondering if it might be possible for has_many :through to generate a WHERE query sometimes, instead of always doing an INNER JOIN? For example:
classCompany < ActiveRecord::Base
classRecord < ActiveRecord::Base
classUser < ActiveRecord::Base
has_many :records, through::company
When you call user.records, I would expect it to just run a plain WHERE query, instead of doing an INNER JOIN. Rails already knows that the User belongs to the Company, and it knows that a Company has many Records, so I think it's safe to skip the join in this case.
I imagine there are a lot of edge cases that could make this tricky, but I think it might be nice if trivial cases like this were supported.
I'm nervous about posting this message, because I have the feeling that I'm forgetting something obvious. I know I can write: