CakePHP3-如何获得子元素的多个关联

CakePHP3-如何获得子元素的多个关联,cakephp,Cakephp,我有一个具有树行为的客户控制器来存储该系列: 这正如预期的那样有效 e、 g: id | parent_id | type | name ----|-----------|---------|-------------- 1 | NULL | husband | Jon Doe 2 | 1 | wife | Jane Doe 3 | 1 | child | Jim Doe 我还有一个合同控制员,它与客户正确关联 合同

我有一个具有树行为的客户控制器来存储该系列:

这正如预期的那样有效

e、 g:

id  | parent_id | type    | name
----|-----------|---------|--------------
1   | NULL      | husband | Jon Doe 
2   | 1         | wife    | Jane Doe 
3   | 1         | child   | Jim Doe 
我还有一个合同控制员,它与客户正确关联

合同稳定:

$this->belongsTo('Customers', [
    'foreignKey' => 'customer_id',
    'joinType' => 'INNER'
]);
可定制:

$this->belongsTo('ParentCustomers', [
    'className' => 'Customers',
    'foreignKey' => 'parent_id'
]);
$this->hasMany('ChildCustomers', [
    'className' => 'Customers',
    'foreignKey' => 'parent_id'
]);

$this->hasMany('Contracts');
客户视图()

这对父客户(丈夫)来说是正常的。我得到一个像这样的物体:

object(App\Model\Entity\Customer) {
    'id' => (int) 1,
    'parent_id' => null,
    'typ' => 'husband',
    'name' => 'Jon Doe',
    'contracts' => [
     (int) 0 => object(App\Model\Entity\Contract) {
        'id' => (int) 1,
        'customer_id' => (int) 1,
        'contract_number' => '123456',
        'tariff' => 'SuperTariff ABC'
    }
    'child_customers' => [
     (int) 0 => object(App\Model\Entity\Customer) {
        'id' => (int) 2,
        'parent_id' => (int) 1,
        'typ' => 'wife',
        'name' => 'Jane Doe'
     },
      (int) 1 => object(App\Model\Entity\Customer) {
        'id' => (int) 3,
        'parent_id' => (int) 1,
        'type' => 'child',
        'name' => 'Jim Doe'
    }
}
但儿童客户(妻子和/或孩子)也有合同,但未显示这些合同。是否有一种“cakephp”方法可以做到这一点,或者我应该为每个客户收集数据

提前谢谢

object(App\Model\Entity\Customer) {
    'id' => (int) 1,
    'parent_id' => null,
    'typ' => 'husband',
    'name' => 'Jon Doe',
    'contracts' => [
     (int) 0 => object(App\Model\Entity\Contract) {
        'id' => (int) 1,
        'customer_id' => (int) 1,
        'contract_number' => '123456',
        'tariff' => 'SuperTariff ABC'
    }
    'child_customers' => [
     (int) 0 => object(App\Model\Entity\Customer) {
        'id' => (int) 2,
        'parent_id' => (int) 1,
        'typ' => 'wife',
        'name' => 'Jane Doe'
     },
      (int) 1 => object(App\Model\Entity\Customer) {
        'id' => (int) 3,
        'parent_id' => (int) 1,
        'type' => 'child',
        'name' => 'Jim Doe'
    }
}