如何从查询生成器数据数组中删除 CakePHP 3 关联模型?
How to remove CakePHP 3 Association Model from Query Builder Data array?
My Query
is look like -
$Fields = ['MyModel.a','MyModel.b','OtherModel.c','OtherModel.d'];
$data = $this->MyModel->find('all')
->select($Fields)
->join([
'OtherModel' => [
'table' => 'other_model_table',
'type' => 'LEFT',
'conditions' =>[
'MyModel.uniqueid'=>'OtherModel.uniqueid'
]
]
]);
From above Query, Output
is look like -
[
'a' => 'some_value',
'b' => 'some_value',
'OtherModel' => [
'c' => 'some_value',
'd' => 'some_value'
]
]
But my Expected Output
is look like -
[
'a' => 'some_value',
'b' => 'some_value',
'c' => 'some_value',
'd' => 'some_value'
]
有什么解决办法吗?
您必须为其他字段使用自定义别名table:
$Fields = [
'MyModel.a',
'MyModel.b',
'c' => 'OtherModel.c',
'd' => 'OtherModel.d'
];
另见
My
Query
is look like -
$Fields = ['MyModel.a','MyModel.b','OtherModel.c','OtherModel.d'];
$data = $this->MyModel->find('all')
->select($Fields)
->join([
'OtherModel' => [
'table' => 'other_model_table',
'type' => 'LEFT',
'conditions' =>[
'MyModel.uniqueid'=>'OtherModel.uniqueid'
]
]
]);
From above Query,
Output
is look like -
[
'a' => 'some_value',
'b' => 'some_value',
'OtherModel' => [
'c' => 'some_value',
'd' => 'some_value'
]
]
But my
Expected Output
is look like -
[
'a' => 'some_value',
'b' => 'some_value',
'c' => 'some_value',
'd' => 'some_value'
]
有什么解决办法吗?
您必须为其他字段使用自定义别名table:
$Fields = [
'MyModel.a',
'MyModel.b',
'c' => 'OtherModel.c',
'd' => 'OtherModel.d'
];
另见