Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Generate: uses int in migration, mysql_timestamp in model observer
  • Just created a model/migration from Oil:

    migration:

    'created_at' => array('constraint' => 11, 'type' => 'int'),
    'updated_at' => array('constraint' => 11, 'type' => 'int'),


    model:

    protected static $_observers = array(
    'Orm\Observer_CreatedAt' => array(
    'events' => array('before_insert'),
    'mysql_timestamp' => false,
    ),
    'Orm\Observer_UpdatedAt' => array(
    'events' => array('before_save'),
    'mysql_timestamp' => false,
    ),
    );


    Any ideas? Is this normal?



    1.4
  • What do you mean, normal?

    That ORM models by default include the timestamps?
  • Yeah it doesn’t work at the moment, because the timestamps don’t get updated, whenever you do a create or update, it just sets the int to 0. Seems like a pretty big bug to me, so I’m confused to whether I’ve missed something!
  • HarroHarro
    Accepted Answer
    That is odd, can you create an issue for it on http://github.com/fuel/orm/issues ?
  • I get this issue if I have anything but INT as the MySQL datatype for the columns.  If MySQL is set to TIMESTAMP or DATETIME even if the Model CRUD observer property mysql_timestamp set to true, I get zeros.  However, setting the following static properties does have the desired effect:

        protected static $_mysql_timestamp = true;
        protected static $_created_at = 'created_at';
        protected static $_updated_at = 'updated_at';

    Stepping through the code, I couldn't actually see where the observers were being called so I just removed them.
  • Model_Crud works differently from ORM.

    If you look in the code, you'll see that both properties are checked and used in the save() method. You should define the column as DATETIME when $_mysql_timestamp is true, and as INT if it's false.

    If you get zero's, do you mean '0000-00-00 00:00:00' as DATETIME value? TIMESTAMP is incorrect, that's shouldn't work. If this is the case, what does

    echo \Date::forge()->format('mysql');

    return on your system?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion