Note that there are some explanatory texts on larger screens.

plurals
  1. POFind on models with HasAndBelongsToMany relationship returns unexpected format in Cakephp
    primarykey
    data
    text
    <p>I'm working on tagging system in cakephp. Tags can be children of other tags that are roots. (No children of children).</p> <p>The models are User and Tag. Their relationships look like this:</p> <pre><code>//User.php: public $hasAndBelongsToMany = array( 'Tag' =&gt; array( 'className' =&gt; 'Tag', 'joinTable' =&gt; 'users_tags', 'foreignKey' =&gt; 'user_id', 'associationForeignKey' =&gt; 'tag_id', 'unique' =&gt; true, ), ); //Tag.php: var $belongsTo = array( 'Parent' =&gt; array( 'className' =&gt; 'Tag', 'foreignKey' =&gt; 'parent_id', 'dependent' =&gt; true, ), ); </code></pre> <p>When I try to do a simple paginate, like so,</p> <pre><code>$this-&gt;User-&gt;recursive = 2; $this-&gt;set('users', $this-&gt;paginate()); </code></pre> <p>I get some weird results that look like this:</p> <pre><code>array( (int) 0 =&gt; array( 'User' =&gt; array( ... ), 'Tag' =&gt; array( (int) 0 =&gt; array( 'id' =&gt; '1', 'parent_id' =&gt; null, ... 'Parent' =&gt; array() ), (int) 1 =&gt; array( 'id' =&gt; '2', 'parent_id' =&gt; '1', ... 'Parent' =&gt; array( 'id' =&gt; '1', 'parent_id' =&gt; null, ... ) ) ) ), (int) 1 =&gt; array( 'User' =&gt; array( ... ), 'Tag' =&gt; array( (int) 0 =&gt; array( 'id' =&gt; '1', 'parent_id' =&gt; null, ... 'Parent' =&gt; array( 'Parent' =&gt; array() //What's up with this parent inside the parent? ) ), (int) 1 =&gt; array( 'id' =&gt; '2', 'parent_id' =&gt; '1', ... 'Parent' =&gt; array( 'id' =&gt; '1', 'parent_id' =&gt; null, ... ) ) ) ) </code></pre> <p>)</p> <p>You'll notice that the tag that returned weird results is actually the same tag (id #1) as the first tag in the array. I'm confused as to why it would be right before, and wrong the second time..? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload