Mario Estrada Tue Aug 31 15:02:51 -0400 2010

Subject: Aggregate & Other Functions

How do i get the total count of a certain query?
'select count(*) from table'
Is it only possible by the 'find_by_sql' method?

I want a certain attribute to have its default value to 'NOW', how can I achieve this the attribute is name 'fecha_ingreso' I know I can add a column named 'created_at' and it will be filled automatically but that's not what I want. How can I use a direct db expression like NOW for filling a column? Is the only way only with php date or similar?


Jacques Fuentes Tue Aug 31 18:46:44 -0400 2010

To get a count from a table you do the following

$integer = MyModel::count(); # select count(*) as n from my_model

$integer will now be an int, not an object.

We do not have a way to use a db function like NOW for your timestamp. Right now the way for you to do this would be to use a before_create callback and set the date/time there.