Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP read in hasMany through relationship
    text
    copied!<p>Trying to display related data from a hasMany through table. It's finding the joinModel but not extending to the other table's data.</p> <p><strong>Item Model</strong>:</p> <pre><code>class Item extends AppModel { public $name = 'Item'; public $belongsTo = array('Category'); public $hasMany = array('GroclistItem'); } </code></pre> <p><strong>Groclist Model</strong>:</p> <pre><code>class Groclist extends AppModel { public $name = 'Groclist'; public $belongsTo = array('Category'); public $hasMany = array('GroclistItem'); } </code></pre> <p><strong>GroclistItem Model</strong>:</p> <pre><code>class GroclistItem extends AppModel { public $name = 'GroclistItem'; public $belongsTo = array('Groclist', 'Item'); public $useTable = 'groclists_items'; } </code></pre> <p><strong>GroclistController View Action</strong>:</p> <pre><code>public function view($id = null) { if (!$id) { $this-&gt;Session-&gt;setFlash(__('Invalid list', true)); $this-&gt;redirect(array('action' =&gt; 'index')); } $this-&gt;set('groclist', $this-&gt;Groclist-&gt;read(null, $id)); } </code></pre> <p><strong>Debug of $groclist</strong>:</p> <pre><code>app\View\Groclists\view.ctp (line 80) Array ( [Groclist] =&gt; Array ( [id] =&gt; 3 [name] =&gt; This Week [user_id] =&gt; [sunday] =&gt; Pizza [monday] =&gt; Scallops [tuesday] =&gt; Stuffed Mushrooms [wednesday] =&gt; Mustard Chicken with Daulphanois Potatoes [thursday] =&gt; Sizzling Chicken and Cheese [friday] =&gt; Walkabout Soup with Beer Bread [saturday] =&gt; Paradise Indian [created] =&gt; 2011-09-15 14:42:55 [modified] =&gt; 2012-02-19 16:51:00 ) [GroclistItem] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 18 [item_id] =&gt; 24 [groclist_id] =&gt; 3 ) [1] =&gt; Array ( [id] =&gt; 17 [item_id] =&gt; 23 [groclist_id] =&gt; 3 ) ) ) </code></pre> <p>I would like the GroclistItem array to display the item data which should be a grocery list item such as Diet Coke or Soap. It's finding the correct associations in there.</p>
 

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