I don’t think you specify DataTypes.DATE to cast it. It does not work like that as sequelize will try to save it like that in database 2019-01-02 so it cannot work.
collection('myModel', {
fields: [{
field: 'expirationTimeDate',
type: 'Date',
get(record) {
return new Date(record.expirationTime);
},
set(record, expirationTimeDate) {
// I don't know if expirationTimeDate is a date here or a string. I will consider it as a Date
record.expirationTime = expirationTimeDate.getTime();
return record;
},
});
If that is the case we have an issue because after adding this field scheme is not updated and we could not see it in the layout. What reasons should be to not updating the scheme? I guess this is the reason why this example didn’t solve the problem completely. We tried another way without extra fields.
We solved half of the problem, getting proper date now is working after modifying get(record) with this:
When we try the same with the set(record) we could not do the similar:
set(record) {
console.log(record); // It's look like not getting here at all. Probably some syntax problem?
record.expirationTime = (new Date(record.expirationTime).getTime()/1000);
return record.expirationTime;
},
still have an error:
Data truncated for column 'expiration_time' at row 1
The .forestadmin-schema.json should contains a definition of your newly added field (After a server restart).
Looking at the smart field documentation, it seems that set should take more than one parameter if I’m correct.
Could you please share the complete configuration of your smart field so I could also try it myself ?