How to remove a key ( field ) from Lucid model



I’ve defined a hook for my lucid model like this

static boot () {
	this.addHook('afterFind', async (offer) => {
		offer.farsi_created_at = Functions.en_date_2_fa_date(offer.created_at);

which adds a farsi_created_at property to object after finding it.

but when I want to save the model, it returns this error

ER_BAD_FIELD_ERROR: Unknown column 'farsi_created_at' in 'field list' 

which seems true because this field which I’ve added in find hook doesn’t exist in the offers table

I tried to delete the added property in beforeUpdate hook like this:

this.addHook('beforeUpdate', async (offer) => {
	delete offer['farsi_created_at']

but I still get the same error and property still exists in the object of model.

How can I delete properties that I added to the object before save ?


Getters or Computed properties


It’s another way of implementing but for, sync only, code.
I want to know how can I delete a key from Lucid Model


Why want you add a property and not saving it while you can create a virtual property which will do what you want automatically…?


Getters are synchronous, which means you cannot run asynchronous code inside them. You must use hooks for that.

because getters cannot run async code and I want to run async code.
That date is just an example in this question.

and the reason Why I want is something outside the scope of this question.


Simply add it to the sideloaded object that each model has.

modelInstance.$sideLoaded.myprop = value