Describe the bug
Timestampable behavior does not work.
The field created_at is not filled when creating or saving a record and methods create(), save() return false
To Reproduce
Steps to reproduce the behavior:
class Test extends Model
{
public $id;
public $data;
public $created_at;
public function initialize()
{
$this->addBehavior(new Timestampable(
[
'beforeCreate' => [ // and onCreate
'field' => 'created_at',
],
]
));
}
}
Details
Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.case_insensitive_column_map => Off => Off
phalcon.orm.cast_last_insert_id_to_int => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.exception_on_failed_metadata_save => On => On
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On
Try to add 'format' => 'Y-m-d H:i:s',
'beforeCreate' => [ // and onCreate
'field' => 'created_at',
'format' => 'Y-m-d H:i:s',
],
@Jeckerson It does not help.
The format option is optional and everything should have worked without it
@ekmst, It's not a bug.
Try to change 'beforeCreate' to 'beforeValidationOnCreate'
I know that it resolve your problem.
class Test extends Model
{
public $id;
public $data;
public $created_at;
public function initialize()
{
$this->addBehavior(new Timestampable(
[
'beforeValidationOnCreate' => [ // and onCreate
'field' => 'created_at',
'format' => 'Y-m-d H:i:s'
],
]
));
}
}
Don't forget about validation please.
If the create or update operations return false You can get error messages by calling the
"getMessages()" method.
@TimurFlush Yes, I am aware of getMessages(), but in my case, he did not return anything.
But beforeValidationOnCreate helped. Thank you!
Most helpful comment
@TimurFlush Yes, I am aware of
getMessages(), but in my case, he did not return anything.But
beforeValidationOnCreatehelped. Thank you!