Why is formatDates function not invoked?


#1

I use this function in my model, but after tinkering with console.log, I think it isn’t even invoked.
I wonder where I do wrong?

  static formatDates(field, value) {
    console.log('test');

    if (field === 'period') {
      return value.format('YYYY-MM-DD');
    }
    return super.formatDates(field, value);
  }

#2

Wait, I think I was missing the point in the docs. It is invoked when saving model, not when fetching.


#3

Yup you must use castDates for that http://adonisjs.com/docs/4.0/lucid#_casting_dates