忽略了Doctrine生成的SQL的鉴别器部分

忽略了Doctrine生成的SQL的鉴别器部分,第1张

忽略了Doctrine生成的SQL的鉴别器部分

这是我能想到的解决方案。想法是扩展一些学说类以添加所需的功能。保持模型不变。

创建扩展SqlWalker的新类(当然是更新名称空间)

<?phpnamespace Sad;use DoctrineORMMappingClassmetadata;use DoctrineORMQuerySqlWalker;class CustomSqlWalker extends SqlWalker{  const IGNORE_DISCRIMINATION = 'ignoreDiscrimination';    public function walkWhereClause($whereClause)  {    // Get list of aliases in which discrimination should be ignored    $ignoreDescription = $this->getQuery()->getHint(self::IGNORE_DISCRIMINATION);    if ($ignoreDescription !== false) {      // For each aliases...      foreach ($this->getQueryComponents() as $k => $component) {        // ...check if alias is in ignore list        if (in_array($k, $ignoreDescription)) {                    $metaObj = $component['metadata'];          // Update inheritance type to disable discrimination where          if ($metaObj->isInheritanceTypeSingleTable()) { $metaObj->setInheritanceType(Classmetadata::INHERITANCE_TYPE_NONE);          }        }      }    }    return parent::walkWhereClause($whereClause);  }}

然后进行查询,您可以执行以下 *** 作:

echo $entityManager->createQuery("SELECT p FROM SadSchemaAbstractPage as p")->getSQL();// Output: ELECT p0_.id AS id_0, p0_.name AS name_1, p0_.type AS type_2 FROM page p0_ WHERe p0_.type IN ('page', 'link')$query = $entityManager->createQuery("SELECt p FROM SadSchemaAbstractPage as p");// Make sure query uses custom walker$query->setHint(DoctrineORMQuery::HINT_CUSTOM_OUTPUT_WALKER, 'SadCustomSqlWalker');// Specify which aliases should ignore discrimination$query->setHint(SadCustomSqlWalker::IGNORE_DISCRIMINATION, array('p'));echo $query->getSQL();// Output: ELECT p0_.id AS id_0, p0_.name AS name_1, p0_.type AS type_2 FROM page p0_


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4917299.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存