cakephp - 对 hasMany 和 BelongsToMany 模型使用 **joinType** 的替代方法
问题描述
我想获得左侧模型/表格的结果,当且仅当条件在右侧/包含模型中满足 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
)
)
)
)
问题:-
- 为什么hasMany和BelongsToMany关联没有“joinType”选项?
- 我怎样才能存档?我只想得到第 1 个而不是第 0 个
解决方案
推荐阅读
- python - 使用 Flask、gunicorn、gevent 绕过 SSL 证书验证
- python - 我的数据框有多重索引,如何计算一个级别的总和?
- ios - React-Native/XCode 12.4/iOS 模拟器 - 应用启动时出现黑屏
- flutter - 下拉菜单未显示所选值
- python - 使用单个值和元组的组合将字典映射到另一个字典
- matplotlib - seaborn 计数图中的色调传说 | 改变位置
- typescript - tsconfig 中是否有别名的简写?
- plotly - 轴顶视图布局
- node.js - 当 POST 请求成功注销用户并重定向到主页时,正确的状态代码是什么?
- c++ - C++ 复制构造函数导致内存错误