【问题标题】:Doctrine from Symfony ignoring part of my having clause?Symfony 的教义忽略了我的部分有条款?
【发布时间】:2013-03-06 20:17:11
【问题描述】:

我有以下代码:

$sub_questions_no_restricted = Doctrine_Query::create()
                ->select("q2.id")
                ->from("question q2")
                ->leftJoin("q2.CountryRestrictions cr2")
                ->groupBy("q2.id")
                ->having("count(cr2.country_iso)=0");

我想得到所有没有国家限制的问题ID

但是 symfony 没有生成正确的 SQL,忽略了 having 子句的一部分。

生成的 DQL 和 SQL 是:

DQL=SELECT q2.id FROM question q2 LEFT JOIN q2.CountryRestrictions cr2 GROUP BY q2.id HAVING count(cr2.country_iso)=0
SQL=SELECT q.id AS q__id FROM question q LEFT JOIN country_restriction c ON q.id = c.question_id GROUP BY q.id HAVING count(c.country_iso)=)

SQL 忽略“0”,并添加一个“)”

我做错了什么? 它是一个教义问题? 有什么建议吗?

【问题讨论】:

  • 尝试->have("count(cr2.country_iso)='0'");
  • Nop @bleuscyther ,它转换为: HAVING count(c3.id)='0) ) --> 忽略最后一个 ',还有其他建议吗?
  • 尝试

标签: sql doctrine symfony-1.4 having


【解决方案1】:

尝试在有子句的 ) 和 = 之间放置空格。

$sub_questions_no_restricted = Doctrine_Query::create()
                ->select("q2.id")
                ->from("question q2")
                ->leftJoin("q2.CountryRestrictions cr2")
                ->groupBy("q2.id")
                ->having("count(cr2.country_iso) = 0");

【讨论】:

  • 谢谢!有用!但这是一个奇怪的错误,它必须在没有空格的情况下工作。 ;)
  • 在我看来有点像 bug
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 2017-11-16
相关资源
最近更新 更多