News for hackers. Stuff that matters.
Re:Learn SQL, dammit by yxhuvud on Wednesday May 08, 2013 @03:09PM (#5676195)
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)

Re:Learn SQL, dammit by pjungwir on Wednesday May 08, 2013 @03:15PM (#5676231)
Well, 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. :-)
Re:Learn SQL, dammit by DrJokepu on Wednesday May 08, 2013 @03:24PM (#5676276)
OP'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.