Browse files

Fixed pluck to be working with selects.

See #9777 for details.

Previously pluck is not returning what we wanted to
Added a test also to make sure it's working fine.
This will also fix the build for 1.8.7 as we 
were doing some sort on hash.

Thanks @pixeltrix for helping me out.

Thanks @linduxed for pairing with me.
  • Loading branch information...
1 parent 6ab3c73 commit de5b89ddc9f9f45760856a1eb55f53a11d067a74 @arunagw arunagw committed May 10, 2013
@@ -181,8 +181,11 @@ def pluck(column_name)
column_name = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
+ result = klass.connection.exec_query(select(column_name).to_sql)
+ last_column = result.columns.last
klass.connection.select_all(select(column_name).arel).map! do |attributes|
- klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes))
+ klass.type_cast_attribute(last_column, klass.initialize_attributes(attributes))
@@ -494,8 +494,9 @@ def test_pluck_with_qualified_column_name
def test_pluck_does_not_replace_select_clause
- taks_relation ="approved, id, id AS foo_id").order(:foo_id)
- assert_equal [false, true, true, true], taks_relation.pluck(:approved)
+ taks_relation ="approved, id, id AS foo_id").order('foo_id DESC')
+ assert_equal [4,3,2,1], taks_relation.pluck(:id)
+ assert_equal [true, true, true, false], taks_relation.pluck(:approved)
def test_pluck_auto_table_name_prefix

3 comments on commit de5b89d


parndt commented on de5b89d Aug 4, 2013

I think this might have caused an issue with JRuby; for some reason it complains of trying to access columns on Array:

       undefined method `columns' for [{"title"=>"Foo"}]:Array

Here's my passing build:
Immediately preceding failing build: (note the two jruby-19mode failures)

Here's how I fixed my build refinery/refinerycms@3eed7ec

Just logging it here for future reference..


rafaelfranca replied Aug 4, 2013


parndt replied Aug 4, 2013

Please sign in to comment.