The only differences are:
- The first method will return duplicate entries where the sales_id for the customer and project both match the users id.
- The second method might not return records where a customer with a matching sales_id does not have a project (no
projects.customer_id
for that customer).
The last difference only matters if a customer does not necessarily have any projects. Otherwise, the second method is better because it avoids dealing with duplicates.
If a customer does not always have a project, a simple workaround would be to use includes
instead of joins
:
Log.includes(:customer_comm_record =>{ :customer => :projects}).
where('customers.sales_id = :id OR projects.sales_id = :id', id: session[:user_id])
This will force a LEFT JOIN and will return customers regardless of whether they are associated with a project.