When creating a model with Oil I realized that that method is always inserted:
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array(
'events' => array('before_insert'),
'mysql_timestamp' => false,
),
'Orm\Observer_UpdatedAt' => array(
'events' => array('before_update'),
'mysql_timestamp' => false,
),
);
Also (with Model_Soft):
protected static $_soft_delete = array(
'mysql_timestamp' => false,
);
But, at the same time, the default value in the Observer classes is false
:
class Observer_UpdatedAt extends Observer
{
/**
* @var bool set true to use mySQL timestamp instead of UNIX timestamp
*/
public static $mysql_timestamp = false;
Is there any need to specify a value that is already the default one?
Bonus: Is there any reason to use datetime
instead of timestamp
by default? (Apart from the remote possibility that my application will be still online after 2038)
Oil puts the default values in for parameters that are most commonly changed after generation. You can omit default values.
Regarding the datetime
/timestamp
question, in MySQL timestamp
is possible to be configured to have a default value of CURRENT_TIMESTAMP
, and to be updated to CURRENT_TIMESTAMP
upon updating. If you need this functionality, datetime
is not sufficient. However datetime
can have the value of 0000-00-00 00:00:00
, which is not possible to represent with a timestamp (if you don't consider null
the same). While created_at
, and updated_at
is designed for a specific purpose, you can always think of using it in a way that is aided by this FuelPHP mechanism, but is a slightly different purpose. In these cases you might need datetime
(to represent dates that are not possible with a timestamp).
I hope this helps.