Forum: Ruby on Rails Possible Active Record bug using :select in find method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fcbeb959b7a9ab6e59ae5b6e7f7d3087?d=identicon&s=25 wolleybook (Guest)
on 2007-04-15 00:11
(Received via mailing list)
Hi,

I am writing a small rails application that uses Ruby(1.8.5) with
ActiveRecord (1.15.3) .

I realized that if i use the find method with the optional
parameter  :select with only the required columns to look for records
in a table with 50,000 records as opposed to a find method without
the :select option, the query is a lot faster. It took me 31 secs in
the former case as opposed to 12 in the latter. I am using MySQL and
my application is running on windows. (And yes, the table that I am
querying is indexed).

Now my problem is that if i use :select the way it is mentioned in the
rails documentation

Item.find( :all, :select =>  [:column1, :column2, :column3] )  or
Item.find( :all, :select =>  ['column1', 'column2', ':column3'] )

It throws an error because it executes a query like:

select column1column2 column3 from items;

when there is no column like column1column2column3 in the table items.

However, If i modify my request  and put a comma after each column
name except on the last one

Item.find( :all, :select =>  ['column1,' ,  'column2,'  ,
'column3'] )

it works because this time it executes the query as noted below:

select column1,column2,column3 from items;

So I guess unless I am using some incompatible version, there could be
a bug in ActiveRecord.
Or am I missing something?


Thanks
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-04-15 01:03
(Received via mailing list)
> Now my problem is that if i use :select the way it is mentioned in the
> rails documentation
>
> Item.find( :all, :select =>  [:column1, :column2, :column3] )  or
> Item.find( :all, :select =>  ['column1', 'column2', ':column3'] )

Where is that in the docs?  :select should be a string.  :select =>
"col1, col2, tbl2.*"


--
Rick Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
Fcbeb959b7a9ab6e59ae5b6e7f7d3087?d=identicon&s=25 wolleybook (Guest)
on 2007-04-15 03:29
(Received via mailing list)
My apologies. I should have checked in the official rails docs.
I was referring to
http://www.rubyonrailsblog.com/articles/2006/10/04....

Thanks for clearing this up.
This topic is locked and can not be replied to.