# ActiveRecord - find

**URL:** <https://www.ruby-forum.com/t/activerecord-find/127764>\
**Category:** Rails\
**Created:** [February 1, 2008, 3:23am UTC](https://www.ruby-forum.com/t/activerecord-find/127764 "2008-02-01T03:23:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [February 1, 2008, 3:23am UTC](https://www.ruby-forum.com/t/activerecord-find/127764/1 "2008-02-01T03:23:32Z")

</div>

Hi-

What I would like to do is select a single column out of my model, say  
the column is called my\_column, and store the result in an array,  
which it should be, right?

For example, if I do:  
@my\_arr = Model.find(:all, :select =\> “my\_column”)

This should fill @my\_arr with all the values from “my\_column”, right?

So then I can access the data by some\_other\_variable = @my\_arr[0], or  
do I have to reference this as an object and do something like  
some\_other\_variable = @my\_arr.my\_column?

Sorry, having a hard time getting this to work.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [February 1, 2008, 2:55pm UTC](https://www.ruby-forum.com/t/activerecord-find/127764/2 "2008-02-01T14:55:58Z")

</div>

I also tried this, and still nothing…any ideas?

Model.find(:all, :select =\> “my\_column”, :order =\> “enterdate  
DESC”).each do |col|  
@arr.push(col.my\_column)  
end

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [February 1, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/activerecord-find/127764/3 "2008-02-01T16:01:34Z")

</div>

pete wrote:

> I also tried this, and still nothing…any ideas?
> 
> Model.find(:all, :select =\> “my\_column”, :order =\> “enterdate  
> DESC”).each do |col|  
> @arr.push(col.my\_column)  
> end

this should work, at least if @arr was initialized as an array:  
@arr = []

in your first post you could have used the form @my\_arr.my\_column  
the finders always return arrays of objects of the model class,  
never pure arrays of strings, otherwise you would lose all the  
class functionality

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [February 1, 2008, 4:19pm UTC](https://www.ruby-forum.com/t/activerecord-find/127764/4 "2008-02-01T16:19:12Z")

</div>

good question 🙂  
had to try that myself, and no, they’re not

did you get any errors in development.log?  
from your questions i assume, that you don’t  
know that very helpful item, so here a short  
explanation:

in your project directory in folder log you’ll  
find a file development.log, where rails writes  
quite a lot of stuff

open it, delete everything in it and then run  
the query. any errors will appear in it  
(and if you access you code from a browser you’ll  
get a lot of info like which controller/action was  
called with which params

with logger.info “text”  
you can write there directly for debugging

eg:

Model.find(:all, :select =\> “my\_column”).each do |col|  
logger.info "foo: #{col.my\_column}  
end

should give you a nice list or the errors

another way to try queries like that is the command  
script/console

this opens irb with all the rails stuff preloaded, so  
you can run queries directly

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [February 1, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/activerecord-find/127764/5 "2008-02-01T16:26:31Z")

</div>

That’s a great tip, thanks, I didn’t know that was there.

As it turns out, I upcased everything and it worked fine. In :select,  
I can leave it any case I want, however when I reference the object, I  
have to use capitals, since that is how it was setup in the DB.

Thanks again for the logging info, that will help tremendously!!!

On Feb 1, 3:19 pm, Thorsten M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [February 1, 2008, 4:11pm UTC](https://www.ruby-forum.com/t/activerecord-find/127764/6 "2008-02-01T16:11:37Z")

</div>

I’m just not getting anything.

Is the column name case sensitive? For example, in MySQL it is  
“MY\_COLUMN”, versus “my\_column”.

On Feb 1, 3:01 pm, Thorsten M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
