First, find does not support the include or join parameter as a parameter. (As mipsy said, it doesn't make sense for find to support include , as this will be the same number of requests as loading later).
Secondly, include impatiently loads the association, so something like
Person.includes(:company)
roughly equivalent to doing:
Person.all.each { |person| Company.find(person.company_id)
I say roughly equivalent, because the former has O(1) (really two) queries, while the latter are O(n) queries, where n is the number of people.
The connection, however, will be just one request, but the disadvantage of the connection is that you cannot always use the extracted data to update the model. To make a connection, you must:
Person.join(:companies)
For more information, see the Rails manual .
To summarize, a join does not load because it does not load the association, and simultaneously loads both pieces of data. I understand that there is a strange fine line between them, but we look forward to loading other data proactively, but you wonβt receive this data later through the connection, or you would have already received it in your original request! Hope this makes sense.
source share