Closed sojimaxi closed 6 years ago
The preferred way of initializing the DateTime field is this:
class ObjectModel extends BaseModel
{
...
public static function fields()
{
return [
...
'created_at' => ['type' => 'datetime', 'value' => new \DateTime()]
];
}
...
}
To be honest your solution is pretty pointless and slow.
"It's not a bug, it's a feature™"
The set{FieldCamelCase} methods are indeed somewhat reserved for setters. Since your getCreatedAt-method returns nothing, I was expecting created_at to be null to be honest.
You have options:
$entity->created_at = new DateTime()
in the event handlerWhat @FlipEverything suggested is probably the easiest, most elegant way.
A little bug should it self while developing my current app and its due to the autoloaded "set{FieldCamelCase}". I think there should be an option to toggle enable or disable on this feature similar to validate.
This make
DBAL
produce an errorCall to undefined method App\\Object::format()
since the value passed toDoctrine\\DBAL\\Types\\DateTimeType->convertToDatabaseValue
was an object instead of string.This bug goes away if I rename the setCreatedAt method to something else.