0
クエリーはうまく実行されますが、Cakesクエリービルダーは結合フィールドをSELECTに追加していません。私はここで何が欠けていますか?ケーキ3.2.10、MySQL、UbuntuCakePHPとの結合3クエリービルダーがデータを返さない
$data = $this->Property->find()
->hydrate(false)
->join([
'PublisherProperty' => [
'table' => 'publisher_property', 'type' => 'inner',
'conditions' => "PublisherProperty.property_id = Property.id AND PublisherProperty.publisher_id = " . $this->Publisher->id
],
'PhysicalAddress' => [
'table' => 'property_address', 'type' => 'inner',
'conditions' => "PhysicalAddress.property_id = Property.id AND PhysicalAddress.type = 'physical'"
],
'CheckinAddress' => [
'table' => 'property_address', 'type' => 'left',
'conditions' => "CheckinAddress.property_id = Property.id AND CheckinAddress.type = 'checkin'"
],
'MainTelephone' => [
'table' => 'property_telephone', 'type' => 'inner',
'conditions' => "MainTelephone.property_id = Property.id AND MainTelephone.type = 'main'"
],
'ReservationTelephone' => [
'table' => 'property_telephone', 'type' => 'left',
'conditions' => "ReservationTelephone.property_id = Property.id AND ReservationTelephone.type = 'reservation'"
],
'PropertyDescription' => [
'table' => 'property_description', 'type' => 'left',
'conditions' => "PropertyDescription.property_id = Property.id AND PropertyDescription.publisher_id IN (" . implode(',',$publishers) . ")",
],
])
->where([
'Property.id' => 1111, //$request->property_id,
'Property.status' => 'ready',
])->first();
これは、クエリビルダが実行して終わるものです:
SELECT
Property.id AS `Property__id`,
Property.property_type_id AS `Property__property_type_id`,
Property.name AS `Property__name`,
Property.parent_company AS `Property__parent_company`,
Property.short_name AS `Property__short_name`,
Property.url AS `Property__url`,
Property.checkin_time AS `Property__checkin_time`,
Property.checkout_time AS `Property__checkout_time`,
Property.cutoff_days AS `Property__cutoff_days`,
Property.cutoff_time AS `Property__cutoff_time`,
Property.desk_open_time AS `Property__desk_open_time`,
Property.desk_close_time AS `Property__desk_close_time`,
Property.checkin_policy AS `Property__checkin_policy`,
Property.room_tax AS `Property__room_tax`,
Property.commission_rate AS `Property__commission_rate`,
Property.status AS `Property__status`,
Property.tripadvisor_location_id AS `Property__tripadvisor_location_id`,
Property.created AS `Property__created`,
Property.modified AS `Property__modified`
FROM
property Property
inner JOIN publisher_property PublisherProperty ON PublisherProperty.property_id = Property.id
AND PublisherProperty.publisher_id = 2
inner JOIN property_address PhysicalAddress ON PhysicalAddress.property_id = Property.id
AND PhysicalAddress.type = 'physical'
left JOIN property_address CheckinAddress ON CheckinAddress.property_id = Property.id
AND CheckinAddress.type = 'checkin'
inner JOIN property_telephone MainTelephone ON MainTelephone.property_id = Property.id
AND MainTelephone.type = 'main'
left JOIN property_telephone ReservationTelephone ON ReservationTelephone.property_id = Property.id
AND ReservationTelephone.type = 'reservation'
left JOIN property_description PropertyDescription ON PropertyDescription.property_id = Property.id
AND PropertyDescription.publisher_id IN (2, NULL)
WHERE
(
Property.id = 1111
AND Property.status = 'ready'
)
LIMIT
1
編集:任意の「なぜあなたはそれをこのようにやっている」ものを避けるために。私は、データベースの命名規則がケーキ命名規則にきちんと適合せず、リレーションシップが少し複雑であるレガシーアプリケーションを書き直しています。含まれていれば効率的にデータベースに照会していればORMを使用します。