phpcakephptreecakephp-2.2

CakePHP Tree Behavior issue - first entry


I'm having an issue with initiating the Tree behavior issue in CakePHP. I have set up the table with lft, rght and parent_id columns.

I'm adding a first entry which other can refer to with the parent_id column. However, the referring does not work as I want.

The first entry is added to the database as expected. If I don't specify parent_id that column will get NULL as database value. The lft and rght columns is also getting NULL as value. I'm not sure if that's what it's supposed to do.

When I'm trying to add a new entry after the initial one, the save will fail.

I've tried to set the lft and rght columns to 1, 1 and 1, 2 on the first entry, but without any luck.

Am I doing something wrong here?


Solution

  • You definitely do not want to set lft and rght. Those are handled by the framework. Do you have them defaulting to null as the docs specify?

    I have always set the parent_id when using Tree Behavior and then CakePHP automagically handles the tree structure based on the parent id. if you need to move the item within the branch, then you can use the other functions of the behavior to do that.

    Try setting just the parent_id and then save. Let me know if that doesn't work.