php多租户配置添加where,php – Doctrine在WHERE子句中过滤而不是LEFT JOIN

作者探讨了在多租户应用程序中如何调整DoctrineFilters,使其能在查询ProjectMembers时将客户端过滤条件正确地添加到WHERE子句而非LEFT JOIN,以实现有效的过滤。讨论了遇到的问题及可能的解决方案策略。
摘要由CSDN通过智能技术生成

我有一个多租户应用程序,我正在使用

Doctrine Filters来过滤我的SQL客户端.

所以,当我想要一个我的客户端项目列表时,我只需要做一个“getAll”,过滤器会自动在WHERE子句上附加SQL,如下所示:

SELECT *

FROM projects p

WHERE p.client_id = 1 #(appended by the filter)

我的问题是当我想要例如ProjectMembers时.过滤器将SQL添加到LEFT JOIN,而不是WHERE子句,使得过滤器无用,因为它将返回所有ProjectMembers,即使它们不是来自客户端1.

SELECT *

FROM projects p

LEFT JOIN project_members pm ON pm.project_id = p.id

AND p.client_id = 1 #(appended by the filter)

这是我的addFilterConstrait

public function addFilterConstraint(ClassMetaData $targetEntity, $targetTableAlias)

{

$class = $targetEntity->getName();

if (array_key_exists($class, $this->disabled) && $this->disabled[$class] === true) {

return '';

} elseif (array_key_exists($targetEntity->rootEntityName, $this->disabled) && $this->disabled[$targetEntity->rootEntityName] === true) {

return '';

}

$config = $this->getFilterConfig($targetEntity->getReflectionClass());

if (!isset($config['clientFilter']) || !$config['clientFilter']) {

return '';

}

return $targetTableAlias. '.' . $config['columnName'] . ' = ' . $this->getParameter('client'); // getParameter applies quoting automatically

}

任何想法如何解决这个问题,将过滤器添加到WHERE而不是LEFT JOIN?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值