Creating Association with condition using other association in CakePHP 3
<p>I'm building a cake php 3 app. My app model includes 3 Tables (amongst others):</p>

<ul>
<li>Structures</li>
<li>MeasuringPoints</li>
<li>DeviceTypes</li>
</ul>

<p>where each Strcuture can have multiple MeasuringPoints:</p>

<pre><code>// StrcuturesTable.php
...
public function initialize(array $config)
{
    parent::initialize($config);

    ...

    $this-&gt;hasMany('MeasuringPoints', [
        'foreignKey' =&gt; 'structure_id'
    ]);
}
</code></pre>

<p>Further, each measuring point is of a certain device type:</p>

<pre><code>// MeasuringPointsTable.php
...
public function initialize(array $config)
{
    parent::initialize($config);
    ...
    $this-&gt;belongsTo('DeviceTypes', [
        'foreignKey' =&gt; 'device_type_id',
        'joinType' =&gt; 'INNER'
    ]);
}
</code></pre>

<p>What i'm lookong for, is how to create a 'SpecialMeasuringPoints' association in the Structure table.</p>

<p>Somewhat like:</p>

<pre><code>// MeasuringPointsTable.php
...
    $this-&gt;hasMany('SpecialMeasuringPoints',[
            'className' =&gt; 'MeasuringPoints',
            'foreignKey' =&gt; 'structure_id',
            'conditions' =&gt; ['MeasuringPoints.DeviceTypes.id'=&gt;1]
    ]);
</code></pre>

<p>As you may see, I want only those measuring points, whose associated device type has the id 1.
However, the previous association condition is not valid; and i have no clue how to correctly implement this.</p>

<p>Any help is appreciated.</p>