Retrieving Nested Referral Data in CakePHP 3.x
<p>I'm trying to figure out how it's possible to get the value of a nested child object in CakePHP 3.x</p>

<p>A basic example consists of three entities:</p>

<p>Server, Rack, Operating_System</p>

<p>Tables:</p>

<p>Racks - id, name</p>

<p>Servers - id, hostname, rack_id, operating_system_id</p>

<p>Operating_systems - id, name</p>

<p>Rack hasMany Servers</p>

<p>Server belongsTo OperatingSystems &amp; belongsTo Racks</p>

<p>How can I reference Rack->Server->OperatingSystem->name in my Rack View?</p>

<pre><code>//View.ctp
&lt;?php foreach ($rack-&gt;servers as $servers):
echo h($servers-&gt;hostname) 
echo h($servers-&gt;operating_system-&gt;name)   //Doesn't output OS Name
endforeach; ?&gt;

//View Function in RacksController:
public function view($id = null)
{
    $rack = $this-&gt;Racks-&gt;get($id, [
        'contain' =&gt; ['Servers']
    ]);
    $this-&gt;set('rack', $rack);
    $this-&gt;set('_serialize', ['rack']);
}
</code></pre>

<p>Not sure if this ends up being a custom query in the controller or if there is a built-in Cake syntax to accomplish what I need.  Thanks for any help.</p>