3 ms·
Why would you ever want to use such a horrible statement instead of using an inner join? scope :with_assignments, joins(:assignments) (or :assignment, dependi
by yxhuvud 14y ago
Why would you ever want to use such a horrible statement instead of using an inner join?
scope :with_assignments, joins(:assignments)
(or :assignment, depending on how your association is defined)
- pjungwir 14y agoWell, adding joins to the outermost query can limit your options re how you use the scope. For instance, `joins` sets a read-only flag on the AR result, so you can't say Employee.with_assignments.destroy_all, for example, to, um, fire all your busy people. :-)
- DrJokepu 14y agoOP's query is not the same as an inner join; it will only return each employee only once while your query will return each employee for every assignment it is associated with.