Find on models with HasAndBelongsToMany relationship returns unexpected format in Cakephp -


i'm working on tagging system in cakephp. tags can children of other tags roots. (no children of children).

the models user , tag. relationships this:

//user.php:  public $hasandbelongstomany = array(         'tag' => array(             'classname' => 'tag',             'jointable' => 'users_tags',             'foreignkey' => 'user_id',             'associationforeignkey' => 'tag_id',             'unique' => true,         ),     );  //tag.php: var $belongsto = array(         'parent' => array(             'classname' => 'tag',             'foreignkey' => 'parent_id',             'dependent' => true,         ),     ); 

when try simple paginate, so,

$this->user->recursive = 2; $this->set('users', $this->paginate()); 

i weird results this:

array( (int) 0 => array(     'user' => array(         ...     ),     'tag' => array(         (int) 0 => array(             'id' => '1',             'parent_id' => null,             ...             'parent' => array()         ),         (int) 1 => array(             'id' => '2',             'parent_id' => '1',             ...             'parent' => array(                 'id' => '1',                 'parent_id' => null,                 ...             )         )     ) ), (int) 1 => array(     'user' => array(         ...     ),     'tag' => array(         (int) 0 => array(             'id' => '1',             'parent_id' => null,             ...             'parent' => array(                 'parent' => array()  //what's parent inside parent?             )         ),         (int) 1 => array(             'id' => '2',             'parent_id' => '1',             ...             'parent' => array(                 'id' => '1',                 'parent_id' => null,                 ...             )         )     ) ) 

)

you'll notice tag returned weird results same tag (id #1) first tag in array. i'm confused why right before, , wrong second time..?


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -