Mike C Mon May 30 12:16:13 -0400 2011

Subject: Support for setting SQL expressions

I know that you can build your own query and use SQL functions like NOW() in them, but is there any support for settings those values via simple setter methods. For example:

$user = User::find_by_email('');
$user->expire = "`NOW()+INTERVAL 3 DAY`";
$user->save();

Just a suggestion, thanks.


Yoan B Tue May 31 10:02:03 -0400 2011

Unless you go plain SQL you'll have to do that on the PHP side (of the force)

1 $user->expire = new DateTime('@'.strtotime('+3 days'));
David Yu Tue May 31 19:40:03 -0400 2011

I can't seem to find how to override the default created_at.

For example, I want to set created_at to be something earlier and did a

$checkin->created_at = new DateTime($string);

print_r($checkin) returns

Checkin Object
(
[errors] =>
[attributes:ActiveRecord\Model:private] => Array
(
[created_at] => ActiveRecord\DateTime Object
(
[model:ActiveRecord\DateTime:private] => Checkin Object
RECURSION
[attribute_name:ActiveRecord\DateTime:private] => created_at
[date] => 2011-05-21 21:19:03
[timezone_type] => 1
[timezone] => +00:00
)

)

but when it saves, it still saves using NOW or something like that.

(1-3/3)