0

I have CakePHP 1.3 multiple tree in the table and for moveup and movedown i set

    $this->Category->Behaviors->attach('Tree', array(
        'scope' => array(
            'Category.parent_id' => $node['Category']['parent_id'],
        ),
    ));

but also the records are also categorized by type so I also need

            'Category.type' => $node['Category']['type'],

and like this it does not make any difference.

Here is sample of my data:

id | parent_id | lft | rght | Title | type
1  | null      | 1   | 4    | Cat1  | categoory
2  | null      | 5   | 20   | Cat2  | categoory
3  | 2         | 6   | 13   |Cat2.1 | categoory
4  | 2         | 14  | 15   |Cat2.2 | categoory
5  | 2         | 16  | 17   | img1  | image
6  | 1         | 2   | 3    | img1  | image
7  | 2         | 18  | 19   | img2  | image
8  | 3         | 7   | 8    | Post1 | post
9  | 3         | 9   | 10   | Post2 | post
10 | 3         | 11  | 12   |Cat2.1.1| categoory
tereško
  • 58,060
  • 25
  • 98
  • 150
Constantin.FF
  • 687
  • 1
  • 10
  • 23

1 Answers1

1

You should be scoping on the 'type' field not 'parent_id' field. Need to set the scope each time depending on which subtree you want to work with.

$this->{$this->nodeType}->Behaviors->attach('Tree', array(
    'scope' => array(
        'Category.type' => $this->nodeType,
    ),
));
ADmad
  • 8,102
  • 16
  • 18