Friday, January 29, 2010

getparentnode and custom validation rule problem

I wrote a model that act as a tree (mymodel).
In mymodel.php file I coded some custom validation rule.
One of the rules is like the following:

function testmyfield($check) {
$grandfather = $this->getparentnode($this->data['Category']
['parent_id']);
if ($grandfather)
{
$condition=array('Category.id' => $grandfather['Category']
['id']);
$ret=$this->field('afield', $condition);
if ($ret)
return false;
}
return true;
}

When this validation rule gets executed $this->data changes after
getparentnode().
Before it is an array with the values entered in the form.
After it is an array like the following:

[Category] => Array
(
[parent_id] => 23
)

[P1] => Array
(
)

(P1 is a model related to Category)

The record gets saved with some of the (required and not empty) fields
empty. :-(

I don't understand if this can be a bug or if I'm doing something
wrong or in the wrong place.

Thank you
maxx

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: