[Rails] Active Record - Record Count

2012-07-12 Thread Doug Jolley
I have been using ActiveRecord's find_by_sql to obtain the number of records within a date range from a mysql database like this: result = Xyz.find_by_sql("SELECT COUNT(*) as recordcount FROM xyz where rdate > '#{start_date}' and rdate < '#{end_date}'")[0].recordcount The problem with the above a

[Rails] Re: Active Record - Object Wrapping a Table Row

2012-07-08 Thread Doug Jolley
> If you want to be entirely correct, the attributes aren't stored as > individual instance variables - they're stored together in a hash. > That is usually irrelevant though - the important thing is the > accessor methods. Nice to know; but, you're right that we do not really need to know about t

[Rails] Re: Active Record - Object Wrapping a Table Row

2012-07-07 Thread Doug Jolley
> 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. I THINK you are confirming my suspicion. Clearly, the first object (which corresponds to the first table row) is pos[0]. From that I would deduce that pos[0].name i

[Rails] Active Record - Object Wrapping a Table Row

2012-07-07 Thread Doug Jolley
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 L