-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Eager loading with 'includes' overrides 'select' in SQL query #2303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
+1 |
Wouldn'g using preload instead of includes suffice in most cases? |
This seems similar to #6132. |
As a note, this no longer merges cleanly, so a rebase will be needed. |
Man, I'd love to see this fixed. So confusing to have #to_sql output something, but the query that runs is completely different. |
Had a similar problem lately, wanted to run something like this:
You need to replace
with
Can anybody point out why there is a select there in the first place? |
@kommen I mentioned 6 months ago that this needed rebased, are you still interested in following-up with this pull request? |
@steveklabnik Thanks for the reminder. I've rebased the commit onto the 3-1-stable branch. If you want me to open another pull request for 3-2-stable or master, let me know. |
Oh! yes, 3-1-stable isn't getting any non-security fixes these days. The way we prefer it to is to open a pull against master, and then fixes get backported as necessary. So can you please re-submit against master? Thanks! |
…cludes". This didn't work in rails 3.1. See rails#2303 for more information and original pull request.
@steveklabnik Turns out, this is fixed in 3.2 and also master. I've rebased onto master anyway, just in case: #8258 |
This was added in 3.2.12? I fail to override the select |
I have same problem, @the8472 can you show me a example using preload? I'm use Property.group("bla").where("bla").select("DISTINCT ON(table.created_at) table.id, *").includes(bla) |
Property.group("bla").where("bla").select("DISTINCT ON(table.created_at) table.id, *").joins(:bla).preload(:bla) |
I have the same issue in 3.2.12.
Result:
|
Yes, select is still overridden by includes in 3.2.22 |
When creating a query with
select
andincludes
likethe
select
part is ignored when querying the database.However, if
to_sql
is called on the Relation, the query gets constructed directly.to_sql output:
query sent to the db:
See the attached patch for a complete testcase which currently fails.