仅当条件满足hasMany和BelongsToMany关联的右侧/包含模型中的条件时,我想获取左侧模型/表的结果。
据我所知,joinType无法用于 hasMany 和 BelongsToMany 关联,因此我无法使用 InnerJoin ...
这是我的查询
$this->loadModel('Logins');
$x = $this->Logins->find('all', [
'fields' => ['id', 'user_name'],
'contain' => [
'Sites' => ['conditions' => ['site_id' => 10]]
],
]);
pr($x->enableHydration(false)->toArray());
die;
这就是结果
[0] => Array
(
[id] => 13
[user_name] => Mal123
[sites] => Array
(
)
)
[1] => Array
(
[id] => 14
[user_name] => rrc
[sites] => Array
(
[0] => Array
(
[id] => 10
[site_name] => Smelter
[site_location] => NA
[client_id] => 1
[site_status_id] => 1
[_joinData] => Array
(
[id] => 15
[login_id] => 14
[site_id] => 10
)
)
)
)
问题:-