Cphalcon: [BUG]: Timestampable behavior does not work

Created on 30 Sep 2019  路  4Comments  路  Source: phalcon/cphalcon

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

  • Phalcon version: 4.0.0-rc.1

    • Build Date: Sep 29 2019 18:59:05

    • Powered by Zephir: Version 0.12.4-b386980

  • PHP Version: 7.3.9
  • Operating System: linux
  • Installation type: installing via package manager
  • Other related info (Database, table schema): mysql 8.0.17
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
bug unverified

Most helpful comment

@TimurFlush Yes, I am aware of getMessages(), but in my case, he did not return anything.

But beforeValidationOnCreate helped. Thank you!

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings