Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Association validation/update/save inconsistency #1080

Closed
nikolajfrey opened this issue Jul 9, 2021 · 3 comments
Closed

Association validation/update/save inconsistency #1080

nikolajfrey opened this issue Jul 9, 2021 · 3 comments
Labels

Comments

@nikolajfrey
Copy link
Contributor

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 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

@neokoenig neokoenig added the bug label Jul 9, 2021
@nikolajfrey
Copy link
Contributor Author

#1081

@neokoenig
Copy link
Contributor

Thanks! Don't forget to add yourself to the Changelog

@chapmandu
Copy link
Contributor

Added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants