You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently started a job working on a team of Lucee/CFWheels developers and I've been enjoying the experience so far.
I was investigating a bug we had recently where a model's update function was failing (returning false) yet the valid function was returning true, I looked into it, mainly the wheels/model/[nestedproperties.cfm, create.cfm, validations.cfm, and update.cfm] files, and found there to be a bit of inconsistency with the way association validation is handled.
When running model.valid() it seems to only run $validateAssociations as an aside and does not really take into account the associations validity when returning the parent model's validity.
In fact $validateAssociations will always returns true.
But when updating or saving a model, the association validation is taken a little more seriously, and the return of the $saveAssociations function in create.cfm:221 is actually considered and the parent model won't save if any associations fail to save.
Now there doesn't seem to be a good way of access the generated errors of an association that I can see when validating/updating/saving the parent model, and our parent model has a grand total of 47 associations.
So I just wanted to raise a discussion around whether the current pattern is ideal or not, and if there are any established techniques for logging the errors of associations?
I know I can do for (association in model.$classData().associations) { model[association].allErrors() }
but I'm just wondering if the valid function should take the validation of associations into account in its return? And maybe if something like for (association in model.$classData().associations) { model[association].allErrors() } should be built in?
Kindly,
Nikolaj Frey
The text was updated successfully, but these errors were encountered:
Hi CFWheels Team,
I recently started a job working on a team of Lucee/CFWheels developers and I've been enjoying the experience so far.
I was investigating a bug we had recently where a model's update function was failing (returning false) yet the valid function was returning true, I looked into it, mainly the wheels/model/[nestedproperties.cfm, create.cfm, validations.cfm, and update.cfm] files, and found there to be a bit of inconsistency with the way association validation is handled.
When running model.valid() it seems to only run
$validateAssociations
as an aside and does not really take into account the associations validity when returning the parent model's validity.In fact
$validateAssociations
will always returns true.But when updating or saving a model, the association validation is taken a little more seriously, and the return of the
$saveAssociations
function increate.cfm:221
is actually considered and the parent model won't save if any associations fail to save.Now there doesn't seem to be a good way of access the generated errors of an association that I can see when validating/updating/saving the parent model, and our parent model has a grand total of 47 associations.
So I just wanted to raise a discussion around whether the current pattern is ideal or not, and if there are any established techniques for logging the errors of associations?
I know I can do
for (association in model.$classData().associations) { model[association].allErrors() }
but I'm just wondering if the
valid
function should take the validation of associations into account in its return? And maybe if something likefor (association in model.$classData().associations) { model[association].allErrors() }
should be built in?Kindly,
Nikolaj Frey
The text was updated successfully, but these errors were encountered: