This project is archived and is in readonly mode.
query engine: chaining 'includes' method with 'to_sql' method
Reported by fooledbyprimes | June 3rd, 2010 @ 01:51 AM
The to_sql method does not seem to be very consistent. Consider the following two queries:
Person.includes(:users).where("users.username =
'myusername'").to_sql
Person.joins(:users).where("users.username =
'myusername'").to_sql
The second instance returns the full query string showing the
"inner joins." But the first one does not show any "inner join" in
the query string even though we all know there was a join that was
performed.
'to_sql' method should behave consistently especially if framework users are given the impression that to_sql always returns the full query that was used.
Comments and changes to this ticket
-
DHH June 9th, 2010 @ 05:21 PM
- Assigned user set to Pratik
-
Pratik June 9th, 2010 @ 05:27 PM
- State changed from new to invalid
That's because the first one uses joins deterministically and it'd preload users in the case above. So the returned query is correct.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>