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! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Feb 1, 2:22 am, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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) > endthis 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Mueller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Mueller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---