Using the timestamp data type in doctrine fixtures
Please note that to be valid, you have to enclose the value within single quotes. For example, say you have the following (totally useless) schema:
Foobar:
columns:
published_at: { type: timestamp }
And you want to create fixtures for this table. You might go this way (please also note that symfony allows php in fixtures files):
Foobar:
foobar_1:
published_at: <?php echo time(); ?>
Which won't work, since the Doctrine_Validator_Timestamp expects a date in the Y-m-d H:i:s format. So maybe you'll try this one:
published_at: <?php echo date('Y-m-d H:i:s'); ?>
Which still doesn't work, since the value gets converted to an unix timestamp.
The right way is (note the enclosing single quotes):
published_at: '<?php echo date('Y-m-d H:i:s'); ?>'
Yay o//
This behavior is explained in this ticket might help.
Comments
Tu peux aussi faire des trucs ubermudacools comme :
Foobar:
foobar_1: published_at: '<?php echo strtotime('last monday'); ?>'D'ailleurs ça marche aussi avec les fixtures pour Propel, ça. C'est trop la classe.
Mais en fait, avec Doctrine, le plus simple reste quand même d'activer le behavior "Timestampable" :
Foobar:
[...] actAs: Timestampable: created: name: published_at type: timestamp format: Y-m-d HCheers.
en l'occurence mon champs published_at ne correspond pas au created_at :-)
par contre, on m'a susurré à l'oreille qu'on pouvait mettre "NOW()" comme valeur de fixtures et que ça marchait "as expected", mais je n'avions point testé.
J'avais déjà rencontré ce soucis là en chargeant mes fixtures. Merci pour la piqûre de -moustique- de rappel !
Thanks :)