This project is archived and is in readonly mode.
.select and :select in AR does not work correctly with an array
Reported by Josh Kalderimis | May 9th, 2010 @ 01:12 PM | in 3.1
ActiveRecord support for using an array of symbols to specify columns to include in a find no longer works. Instead AR/Arel only uses the last value in the array for the select/projection.
Failing test case is provided.
Comments and changes to this ticket
-
Josh Kalderimis May 9th, 2010 @ 01:21 PM
- no changes were found...
-
Dan Pickett May 9th, 2010 @ 06:38 PM
- Tag changed from activerecord, arel, rails3 to activerecord, arel, bugmash, rails3
-
Neeraj Singh May 11th, 2010 @ 06:09 PM
Attached is a patch against rails3 edge.
@Josh thanks for the failing test.
Current code is given below.
# query_methods.rb selects = @select_values.uniq if selects.present? selects.each do |s| @implicit_readonly = false arel = arel.project(s) if s.present? end else arel = arel.project(quoted_table_name + '.*') end
As you can see for each select column arel.project(s) is being called. However multiple project is specified on arel then the last one wins.
Take a look at this test.
users = Table(:users) users.project(users[:email]).project(users[:phone]).to_sql "SELECT \"users\".\"phone\" FROM \"users\""
The correct way to handle this would be.
users.project(users[:email],users[:phone]).to_sql "SELECT \"users\".\"email\", \"users\".\"phone\" FROM \"users\""
Attached patch provides the all the columns names to get selected columns.
-
Josh Kalderimis May 11th, 2010 @ 07:58 PM
Hi Neeraj Singh,
Can you update the ticket as verified. Also, have the run all the AR tests?
Thanks
Josh
-
Neeraj Singh May 11th, 2010 @ 08:19 PM
- Tag changed from activerecord, arel, bugmash, rails3 to activerecord, arel, bugmash, patch, rails3
yes all the tests are passing. I have updated the tag to 'patched'.
-
Santiago Pastorino May 14th, 2010 @ 06:52 PM
- Milestone cleared.
- State changed from new to verified
Proper patch here, also have the tests made by Josh Kalderimis and maintained as the committer.
-
Neeraj Singh May 14th, 2010 @ 07:44 PM
@Santiago Thanks for the much better fix. Now I know better. :-)
-
Santiago Pastorino May 14th, 2010 @ 11:02 PM
- Milestone set to 3.1
For now you can use :select => "id, name" we need to uniformize the API and allow all methods accept and Array
-
José Valim May 15th, 2010 @ 11:39 AM
- Tag changed from activerecord, arel, bugmash, patch, rails3 to activerecord, arel, patch, rails3
-
Rizwan Reza May 16th, 2010 @ 03:05 AM
- Tag changed from activerecord, arel, patch, rails3 to activerecord, arel, bugmash-review, patch, rails3
-
José Valim May 16th, 2010 @ 09:49 AM
- Tag changed from activerecord, arel, bugmash-review, patch, rails3 to activerecord, arel, patch, rails3
- State changed from verified to open
We discussed this one earlier and decided to postpone to 3.1 since it has other implications in the source code.
-
rails May 4th, 2011 @ 01:00 AM
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails May 4th, 2011 @ 01:00 AM
- State changed from open to stale
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>