preserve custom join table field in before_save
stehlifn opened this issue · 1 comments
Hi,
I'm using an additional field in a join table. When updating a parent record via admin view all existing entries in the join table are deleted and then recreated by MvcModel->update_has_and_belongs_to_many_associations(). A possible workaround to preserve the additional field values is to define a before_save method in my derived model and to grab and add those values there to the model_data parameter. Unfortunately the model_data parameter does not hold the id of the instance that is being updated making it impossible to find the field values. The primary_key is unset in MvcModel->save() a few lines earlier:
unset($model_data[$this->primary_key]);
My fix is to add the id parameter as a second parameter to before_save:
if (!$this->before_save($model_data, $id))
Is there a reason why the id should not be propagated to before_save? I'd be happy to create a pull request containing the line if appreciated.
best regards
Florian
Hi Florian,
If it helps you, and doesn't hurt compatibility with the existing system, I'm happy to consider this pull request. Thanks!
Best,
Robert