The model has a myfield_id field that must follow these rules:
- if parent_id is empty (root) myfield_id can't be blank
- if parent_id is not empty myfield_id must be blank (children)
So I wrote a isUnique validation rule for myfield_id. And it seems to
works if I use the baked add and edit pages.
Then I created another page that uses a javascript widget (tafelTree)
to show the tree and to drag and drop around nodes.
In the controller I created a function that receives the id and the
(new) parent id of a node as a parameter. If node id 1234 with
parent_id 5432 becomes (in javascript) a children of node 8765 my
function receives 1234-8765.
I retrieve the record with:
$category = $this->Category->find('first',
array('conditions' => array('Category.id' =>1234))
);
and try to save it with:
$ret = $this->Category->save(array('parent_id' => 8765));
This fails with a validation error for the isUnique rule.
I put a log line in the isUnique function (in cake/lib.../model.php)
to see what is the "condition" that creates the error and...
(
[or] => Array
(
[Category.myfield_id] =>
)
[Category.id !=] => 1234
)
But this is the same condition that I found when saving that record
using the edit function (with no error).
So I don't understand why there's a validation error when the
condition is the same.
Any suggestion?
Thank you
maxx
p.s. En passent... the childrenCount function doesn't work properly
with my data. It reports a number of nodes greater than the real
number. I "verified" and "reordered" my data but the results of the
function are still wrong.
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:
Post a Comment