On 7 July 2012 17:29, Doug Jolley <li...@ruby-forum.com> wrote: > I'm following through an example provided by DHH in his book, "Agile Web > Development with Rails". This example deals with a database with an > "orders" table that has column names, "name", "email", "address" and > "pay_type". > > The Order class is created thusly: > > class Order < ActiveRecord::Base > end > > Later the example describes one way of reading data from the rows of the > table as follows: > > pos = Order.find(:all, :conditions => "name = 'Dave' and pay_type = > 'po'") > > Then, the author says, "The result will be an array of all matching > rows, each neatly wrapped in an Order object." > > It would have been nice if he had gone on to at least describe some of > the characteristics of this particular object. He doesn't. I have a > feeling that one thing that's important for us to know about this object > is that the values for each field in the table row is contained in an > instance variable with the name of the column heading. I'm not sure if > the raw name of the column heading is massaged in any way, i.e., > singular/plural, upper/lower case, etc. I'm also assuming that there > are accessor methods for these instance variables. What I'd like to > know is whether what I have surmised is, in fact, true. I'd also like > to know if there is anything else that I should know about this object. > Can someone please fill in the blanks for me?
As it states the result is effectively an array of Order objects. So to get the name of the first object one uses pos[0].name. Alternatively one can do things like pos.each do |p| # here you can access p.name, p.pay_type etc. end Colin -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.