Note that there are some explanatory texts on larger screens.

plurals
  1. POcakephp habtm nested data
    primarykey
    data
    text
    <p>I have a HABTM relationship and I'd like to get nested data for a categories table from a product table something like this product array:</p> <pre><code>array( (int) 0 =&gt; array( 'id' =&gt; (int) 1, 'name' =&gt; 'a', 'categories' =&gt; array( (int) 0 =&gt; array( 'id' =&gt; (int) 1 ), (int) 1 =&gt; array( 'id' =&gt; (int) 2 ) ) ), (int) 1 =&gt; array( 'id' =&gt; (int) 2, 'name' =&gt; 'b', 'categories' =&gt; array( (int) 0 =&gt; array( 'id' =&gt; (int) 1 ) ) ) ) </code></pre> <p>Is this possible with cake?</p> <p>EDIT: I will try to explain further what I want to do.</p> <p>Please bear with me, I am new to cake and am having trouble getting to grips it.</p> <p>I have a 'product' table:</p> <pre><code> public $hasAndBelongsToMany = array( 'Category' =&gt; array( 'className' =&gt; 'Category', 'joinTable' =&gt; 'categories_sculptures', 'foreignKey' =&gt; 'sculpture_id', 'associationForeignKey' =&gt; 'category_id', 'unique' =&gt; 'keepExisting' ) ) </code></pre> <p>and a category table:</p> <pre><code> public $hasAndBelongsToMany = array( 'Sculpture' =&gt; array( 'className' =&gt; 'Sculpture', 'joinTable' =&gt; 'categories_sculptures', 'foreignKey' =&gt; 'category_id', 'associationForeignKey' =&gt; 'sculpture_id', 'unique' =&gt; 'keepExisting' ) ); </code></pre> <p>and a category products table:</p> <pre><code> public $belongsTo = array( 'Category' =&gt; array( 'className' =&gt; 'Category', 'foreignKey' =&gt; 'category_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ), 'Sculpture' =&gt; array( 'className' =&gt; 'Sculpture', 'foreignKey' =&gt; 'sculpture_id', 'conditions' =&gt; '', 'fields' =&gt; '', 'order' =&gt; '' ) ); </code></pre> <p>I would like to build a view table of the sculptures and also show in each row which categories each sculpture is in (which could be more than one). As I am new to cake I don't know how I would go about this. If I was just querying mysql I could get this information with a group_concat or a nested select, or inefficiently by looping through first array and querying the category_sculpture table by sculpture key and adding the results to the first array. But I would like to know the best way to get this result the cake way.</p>
    singulars
    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.
 

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