0

蛋糕PHP 3.2.3x

我正在尝试显示右连接中的自定义字段,该字段包含(左连接)另一个表并且它不起作用。包含自定义字段的方式如何起作用。

注意 1:当我摆脱contain()我的 ORM 时,我的工作正如我所料。

$properties = $this->find() 
            ->select([
                'Property.id', 'Property.company_id', 'Property.address1', 'Property.postcode', 
                'Tenancies.property_id', 'Tenancies.start_date', 'Tenancies.end_date', 'Tenancies.deposit_total',
            ])
            ->rightJoin(['Tenancies' => 'tenancy'],[
                'Tenancies.property_id = Property.id',
                'Tenancies.active = 1'
            ])
            ->contain([
                'Tenancies.Tenants' => function($q) {
                    return $q
                        ->select([
                            'Tenants.id', 'Tenants.stage', 'Tenants.tenancy_id', 'Tenants.holding_fee',
                        ])
                        ->where([
                            'active = 1',
                        ]);
                    }
            ])
            ->where(['Property.active = 1', $conditions]);

注 2:生成的 sql 是正确的,但不适用于查询。

'选择Propertyid作为Property__idPropertycompany_id作为 Property__company_idPropertyaddress1作为Property__address1Propertypostcode作为Property__postcodeTenanciesproperty_id作为Tenancies__property_idTenanciesstart_date作为Tenancies__start_dateTenanciesend_date作为Tenancies__end_dateTenancies。从右加入( deposit_totalTenancies.property_id = Property.id AND Tenancies.active = 1) WHERE (Property.active = 1 AND Tenancies__deposit_total. = :c0)'property Propertytenancy TenanciesPropertycompany_id

查询应该只显示 3 个“Tenancies”字段,但它会检索所有Tenancies字段。

(int) 0 => [
    'id' => (int) 102,
    'company_id' => (int) 3,
    'address1' => 'Grace Dieu Court',
    'postcode' => 'LE11 4QH',
    'tenancies' => [
        (int) 0 => [
            'id' => (int) 16,
            'property_id' => (int) 102,
            'landlord_id' => (int) 65,
            'agent_id' => (int) 7,
            'company_id' => (int) 3,
            'bedroom' => (int) -1,
            'created' => object(Cake\I18n\FrozenTime) {
                'time' => '2015-05-08T09:30:41+00:00',
                'timezone' => 'UTC',
                'fixedNowTime' => false             
            },
            'active' => true,
             ...
             ...  ## } The rest of all fileds
            'tenants' => [
                (int) 0 => [
                    'id' => (int) 16,
                    'stage' => (int) 7,
                    'tenancy_id' => (int) 16,
                    'holding_fee' => (float) 50
                ],
                (int) 1 => [
                    'id' => (int) 17,
                    'stage' => (int) 7,
                    'tenancy_id' => (int) 16,
                    'holding_fee' => (float) 50
                ]
            ]
        ]
    ]
],
4

0 回答 0