Tuesday, February 2, 2010

Re: tree behaviour and validation rule problem

On 2 Feb, 15:45, John Andersen <j.andersen...@gmail.com> wrote:
> As I can't see your full code from the moment you retrieve the
> Category and until you try to save it, I can't be sure that you have
> provided the Category.id at the time of saving the updated parent_id.
>
> I just imagine that CakePHP actually may try to add a new record, in
> which case the isUnique should fail.

I developed my code starting from here:
http://realm3.com/articles/drag_and_drop_trees_with_cakephp
At the end of the page there's a "save" function and my code is almost
equal to that one.

$category = $this->Category->find('first', array('conditions' => array
(
'Category.id' => $this_node_id)
));
$this->Category->set($category);
if (isset($category['Category']['id']) && $category['Category']
['parent_id'] !== $this_node_parent_id) {
$ret = $this->Category->save(array('parent_id' =>
$this_node_parent_id));
(the names of the variables are obvious.)

The original code used SetParent that, as you know, is deprecated
now.

I didn't use $this->Category->id = 1234 before $this->Category->save
() because I presumed that find('first') would have the same effect
with the ActiveRecord approach. But I could be totally wrong on this.
And because, before adding the isUnique validation rule, my "save"
function did work.

Anyway, I just added $this->Category->id=1234; before $this->Category-
>save() and the problem is still there. :-(

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: