1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix pluck when columns/tables are reserved words.

This commit is contained in:
Ian Lesperance 2012-09-05 18:00:07 -04:00
parent 1c8539da47
commit c7d752fe2f
5 changed files with 21 additions and 3 deletions

View file

@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
* Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
*Ian Lesperance*
* Fix time column type casting for invalid time string values to correctly return nil.
*Adam Meehan*

View file

@ -156,7 +156,7 @@ module ActiveRecord
def pluck(*column_names)
column_names.map! do |column_name|
if column_name.is_a?(Symbol) && self.column_names.include?(column_name.to_s)
"#{table_name}.#{column_name}"
"#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
else
column_name
end

View file

@ -1,10 +1,11 @@
require "cases/helper"
require 'models/club'
require 'models/company'
require "models/contract"
require 'models/topic'
require 'models/edge'
require 'models/club'
require 'models/organization'
require 'models/possession'
require 'models/topic'
Company.has_many :accounts
@ -576,4 +577,10 @@ class CalculationsTest < ActiveRecord::TestCase
assert_equal ["37signals", nil], companies_and_developers.first
assert_equal ["test", 7], companies_and_developers.last
end
def test_pluck_with_reserved_words
Possession.create!(:where => "Over There")
assert_equal ["Over There"], Possession.pluck(:where)
end
end

View file

@ -0,0 +1,3 @@
class Possession < ActiveRecord::Base
self.table_name = 'having'
end

View file

@ -285,6 +285,10 @@ ActiveRecord::Schema.define do
t.string :info
end
create_table :having, :force => true do |t|
t.string :where
end
create_table :guids, :force => true do |t|
t.column :key, :string
end