Hi
I have a model related by another one
the schema's are:
model1: id, default_model2_id (null is permitted)
model2: id, model1_id (is required!)
I want to save them but there is a problem
If the first model when it is new record, there is not id yet to save the second model.
So in this case I save the first model on beforeSave and on afterSave I save the second one and update the first one
pseudocode
The problem is the update function invokes the beforeSave again, causing infinite loop!
Does anyone has a robust way to solve this problem?
I could set a flag on the afterSave method to prevent the beforeSave again but I want a better aproach!
Thanks
I have a model related by another one
the schema's are:
model1: id, default_model2_id (null is permitted)
model2: id, model1_id (is required!)
I want to save them but there is a problem
If the first model when it is new record, there is not id yet to save the second model.
So in this case I save the first model on beforeSave and on afterSave I save the second one and update the first one
pseudocode
beforeSave() { -save the first } afterSave() { -save the second (related with the first model id -> now the id exists!) -update the first one (related with the second model, id just created on the previous line }
The problem is the update function invokes the beforeSave again, causing infinite loop!
Does anyone has a robust way to solve this problem?
I could set a flag on the afterSave method to prevent the beforeSave again but I want a better aproach!
Thanks
