Here is something that "works" under SQL Server (with freetds / odbc) but not mysql.
When renaming columns using the SQL 'as' construct with the mysql adapter, the type is not always preserved.
# script/console
SomeModel.find(:first, :select => 'integer_column').integer_column.class
=> Fixnum
SomeModel.find(:first, :select => 'integer_column as width').width.class
=> String
More detailed:
# cat db/migrate/005_create_noodles.rb class CreateSomeModel < ActiveRecord::Migration def self.up create_table :some_models do |t| t.integer :integer_column end end
def self.down drop_table :some_models end end
# rake db:migrate # script/console>> SomeModel.create(:integer_column => 4) => #<SomeModel id: 1, integer_column: 4>
SomeModel.find(:first, :select => 'integer_column as width').width
=> "4"
_.class
=> String
Under SQL Server get "Fixnum" instead of "String". Fixnum makes more sense to me.
I get the impression the Mysql::Result#each_hash method is responsible. I tried with both Ruby and C implementation do the same.
What should it be?
(I posted this to the Ruby-on-Rails mailing list, but without replies)
Stephan