Inserting stringifiable objects
Ali1 opened this issue · 2 comments
Ali1 commented
I use Chronos quite a lot and I'm in the habit of inserting dates using like this $entity->cancelled = Chronos::now()
(without ->toDateTimeString()
) because during marshalling, they are automatically converted to strings.
I've just realised that it's being audited as a json object string:
(Cake\ORM\Entity)
id 1855
type update
...
original {"cancelled":null}
changed {"cancelled":{"date":"2019-04-23 12:09:18.393806","timezone_type":3,"timezone":"Europe\/London"}}
...
created (Cake\I18n\Time)
You reckon changed properties could be forced into becoming strings in the audit log too to avoid the below? Or are there times when it's useful to have the whole object?
lorenzo commented
If you use FrozenTime::now(), you should get the date serialized as a string, if I remember correctly. FrozenTime is the subclass of Chronos that better integrates with the framework.
Ali1 commented
Yes works perfectly, a nice string now appears. Thank you!