Model Invalidate does not support nested fields #1735

lh-import opened this Issue Oct 11, 2013 · 6 comments


None yet
2 participants

Created by Chickenhen, 12th Jan 2010. (originally Lighthouse ticket #194):

if you have a model with data

$this->data = array('Article' => 
  array('Users' =>
    array('user1' => 'val1', 'user2' => 'val2', 'user3' => 'val3')

from within Article model, call

$this->Invalidate('Users.user1', 'error message');

the form helper will not pick up that the nested field user1 is invalidated.



will not show the associated error message

can try messing with FormHelper::invalidate [sets validation error path], and Helper::tagIsInvalid [tries to extract validation error path]

13th Jan 2010, Mark Story said:

What version is this for? I'm guessing 1.3 but just want to confirm. Also Model::invalidate() does not create array structures using dot syntax, which is probably a key point of failure in your usage. Since tagIsInvalid interprets .'s as arrays, while invalidate does not.

13th Jan 2010, Chickenhen said:

yes - this is v1.3

13th Jan 2010, Chickenhen said:

from the process flow, from using Model::invalidate(), in conjunction with FormHelper::error() [which uses Helper::tagIsInvalid() to determine if an error on a model is set in Model::validationErrors]

I would suggest that Model::invalidate be changed to support the . syntax to create arrays in Model::validationErrors; to make usage consistent, and to properly support model structures.

18th Jan 2010, Chickenhen said:

$this->validationErrors = Set::insert($this->validationErrors, $field, $value);

19th Jan 2010, Chickenhen said:

hrrm... can't edit a comment:

anyways -

to get this working in Model::invalidate(), I changed

$this->validationErrors[$field] = $value


$this->validationErrors = Set::insert($this->validationErrors, $field, $value);

this will slow down validation - as Set::insert is obviously slower than a direct assert. and has not been tested beyond that our current validation calls still pass, and our nested fields are also now invalidated.

form::error() does not behave correctly if you give a path to a field within a model where the field is not a leaf node. I.e.

$this->data = array('Article' => 
  array('Users' =>
    array('user1' => 'val1', 'user2' => 'val2', 'user3' => 'val3')


so possibly the behaviour when called as such should be to invalidate all leaf nodes under a parent.


lorenzo commented Jan 22, 2014

I don't think this is a good idea for 2.x and in 3.0 invalidation will happen directly on the entity level, so there would be no way of porting this feature.

lorenzo closed this Jan 22, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment