Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

query engine: chaining 'includes' method with 'to_sql' method

#4756

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.

Reported by fooledbyprimes · June 3rd, 2010 @ 01:51 AM

State: invalid
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

  1. DHH
    DHH
    • Assigned user set to Pratik

    June 9th, 2010 @ 05:21 PM

  2. Pratik
    Pratik
    • 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.

    June 9th, 2010 @ 05:27 PM