如何在串联连接中使用innerJoinWith()

问题描述 投票:0回答:1

我想一个接一个地加入4个表。为此,我目前正在尝试下面的代码

->innerJoinWith('Districts',function($q){
                return $q->innerJoinWith('Blocks',function($q){
                    return $q->innerJoinWith('Divisions',function($q){
                        return $q->innerJoinWith('Villages');
                    });
                });
            });

我怎么能在一行中总结一下?

php cakephp cakephp-3.0
1个回答
0
投票

你可以使用CakePHP中的关系,https://book.cakephp.org/3.0/en/orm/associations.html在这里你可以得到更多关于它们的细节,

你已经建立了一个关系,你所要做的就是在你的查询中使用“包含”,并获取所有需要的数据。

你可以在这里找到更多关于包含的内容:https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html

© www.soinside.com 2019 - 2024. All rights reserved.