[SOLVED] Deep contain with condition cakePHP 3.5


I am trying to provide a virtual property in my entity Notice
Here are my relations:
Lessors hasMany Properties
Properties hasMany Leases
Leases hasMany Notices

I want to get a property from the Lessor which “owns” the Notice.
Here is my code in Notice.php (entity)

    $lessors    = TableRegistry::get('Lessors');
    $query     = $lessors->find()
        ->contain(['Properties.Leases', function($q) {
           return $q
                'id'  => $this->_properties['lease_id']

got an error:

Illegal offset type in [/var/www/mbail/vendor/cakephp/cakephp/src/ORM/EagerLoader.php, line 413]

What am I doing wrong?

the function needs to be the value of the contain string.


'Properties.Leases' => function (...

Hope that helps :slight_smile:

Thanks Dakota,
It helped :slight_smile:

But I found that the result is not what I am willing to get.
I only want to get the only Lessor that match the condition.
With my corrected query I got all Lessors with their properties and only one containing the Lease.

Need to investigate again then (around Matching I guess)