validation constraints issue#264
Merged
grantcopley merged 7 commits intocoldbox-modules:developmentfrom Mar 23, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes CBWIRE validation behavior so Component.validate( target=someModel ) uses the target model’s constraints (instead of the wire’s), and ensures wire constraints can be discovered whether declared in variables.constraints or this.constraints.
Changes:
- Adjusts
ValidationService.validate()defaulting logic so wire constraints are only applied when validating the wire’s own data. - Updates
Component._getConstraints()to check bothvariablesandthisscopes (preferringvariables). - Adds new TestBox coverage and supporting test-harness fixtures for the above behaviors.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
models/services/ValidationService.cfc |
Changes defaulting of target/constraints to avoid overriding non-wire targets with wire constraints. |
models/Component.cfc |
Enhances _getConstraints() to return constraints from either variables or this scope. |
test-harness/tests/specs/unit/services/ValidationServiceSpec.cfc |
Adds unit tests covering validation of non-wire targets and custom constraints precedence. |
test-harness/tests/specs/CBWIRESpec.cfc |
Adds integration-style assertions for _getConstraints() scope resolution. |
test-harness/models/validationTest.cfc |
Introduces a domain object fixture with constraints for non-wire validation tests. |
test-harness/wires/test/validation/validateConstraints1.cfc / .cfm |
Adds wire fixture declaring constraints via this.constraints. |
test-harness/wires/test/validation/validateConstraints2.cfc / .cfm |
Adds wire fixture declaring constraints via variables.constraints (constraints = ...). |
test-harness/tests/specs/unit/services/ValidationServiceSpec.cfc
Outdated
Show resolved
Hide resolved
test-harness/tests/specs/unit/services/ValidationServiceSpec.cfc
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
07fadb9
into
coldbox-modules:development
9 of 11 checks passed
Collaborator
|
Merged and released as 5.0.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using the
Component.cfcvalidate()method from a wire to validate another model and the wire has constraints defined, it uses the wires constraints to validate and not the constraints defined in the provided model.For example if your wire defines this constraint:
and you have a saveUser action like this:
The
validate()method uses the wires constraints and not theconstraintsdefined in the modelThis pull request also addresses an issue where if the constraints are defined on the wire using the way that cbValidation says to in the documentation, e.g.
this.constraints={}the_getConstraints()method will not return the constraints.https://coldbox-validation.ortusbooks.com/overview/declaring-constraints/domain-object
The
_getConstraints()method has been updated to check both thevariablesandthisscopes to look for constraints. Note: preference is given to thevariablesscope as the cbwire documentation suggests they are defined.https://cbwire.ortusbooks.com/features/form-validation
Component.cfcvalidate()method to only use the wires constraints when it is the wire itself being validatedComponent.cfc_getConstraints()method to also check the this scope for constraintsComponent.cfc_getConstraints()will return constraints from either thevariablesorthisscopes