对hasMany和BelongsToMany模型使用** joinType **的替代方法

时间:2018-12-11 10:44:17

标签: cakephp cakephp-3.0 cakephp-3.x cakephp-3.4

仅当条件满足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
                                )

                        )

                )

        )

问题:-

  1. 为什么对于 hasMany BelongsToMany 关联,没有'joinType'选项?
  2. 如何将其存档?我只想得到第1个而不是第0个

0 个答案:

没有答案