Propel 选择条件中的 IF 语句

发布于 2024-09-18 07:42:55 字数 1603 浏览 3 评论 0原文

我正在尝试将 IF 语句纳入我的推进标准中。 这就是我建立标准的方式:

$c = is_object($c) ? $c : new Criteria();
$c->addSelectColumn("CONCAT(DAYOFYEAR(" . SomePeer::CREATED_AT . "), ' ', YEAR(" . SomePeer::CREATED_AT . ")) AS period");
$c->addSelectColumn("COUNT(" . SomePeer::ID . ") AS registrations");
$c->addSelectColumn("COUNT(IF(" . SomePeer::JOIN . " > 0 AND " . SomePeer::JOIN . " < 3, 1, NULL)) AS coreg");
$c->addJoin(SomePeer::IDENTIFIER, self::TRACKING_IDENTIFIER);
$c->add(SomePeer::ASSOCIATE_ID, $user->getId());
$c->addJoin(self::USER_ID, SomePeer::ID);
$c->addJoin(SomePeer::ID, SomePeer::USER_ID);
$c->add(SomePeer::CREDENTIAL, 'student');
$c->addJoin(SomePeer::PROFILE_ID, SomePeer::ID);

但是,当检查生成的 SQL 时,我得到以下信息:

SELECT CONCAT(MONTHNAME(some_table.CREATED_AT), ' ', YEAR(some_table.CREATED_AT)) AS period, COUNT(some_table.ID) AS registrations, COUNT(IF(some_table.JOIN > 0 AND some_table.JOIN < 3, 1, NULL)) AS coreg 
FROM `some_table`, `>` `0` `AND` `some_table`, `some_table`, `some_table`, `some_table`, `some_table` 
WHERE some_table.ASSOCIATE_ID=:p1 
AND some_table.CREDENTIAL=:p2 
AND some_table.IDENTIFIER=some_table.TRACKING_IDENTIFIER 
AND some_table.STUDENT_USER_ID=some_table.ID 
AND some_table.ID=some_table.USER_ID 
AND some_table.PROFILE_ID=some_table.ID 
# Params: some_table.ASSOCIATE_ID => 6, some_table.CREDENTIAL => 'credential'"

基本上,如您所见,查询的 FROM 部分都是错误的。我猜 propel 将 COUNT 中的 IF 语句的一部分误认为是表名,并将它们包含在查询的 FROM 部分中。 有谁知道我如何解决这个问题,或者有人甚至能够让一些东西发挥作用?

感谢您的帮助,

文森特

I am trying to incorporate an IF statement into my propel criteria.
This is the how I build up my criteria:

$c = is_object($c) ? $c : new Criteria();
$c->addSelectColumn("CONCAT(DAYOFYEAR(" . SomePeer::CREATED_AT . "), ' ', YEAR(" . SomePeer::CREATED_AT . ")) AS period");
$c->addSelectColumn("COUNT(" . SomePeer::ID . ") AS registrations");
$c->addSelectColumn("COUNT(IF(" . SomePeer::JOIN . " > 0 AND " . SomePeer::JOIN . " < 3, 1, NULL)) AS coreg");
$c->addJoin(SomePeer::IDENTIFIER, self::TRACKING_IDENTIFIER);
$c->add(SomePeer::ASSOCIATE_ID, $user->getId());
$c->addJoin(self::USER_ID, SomePeer::ID);
$c->addJoin(SomePeer::ID, SomePeer::USER_ID);
$c->add(SomePeer::CREDENTIAL, 'student');
$c->addJoin(SomePeer::PROFILE_ID, SomePeer::ID);

However when inspecting the resulting SQL I get the following:

SELECT CONCAT(MONTHNAME(some_table.CREATED_AT), ' ', YEAR(some_table.CREATED_AT)) AS period, COUNT(some_table.ID) AS registrations, COUNT(IF(some_table.JOIN > 0 AND some_table.JOIN < 3, 1, NULL)) AS coreg 
FROM `some_table`, `>` `0` `AND` `some_table`, `some_table`, `some_table`, `some_table`, `some_table` 
WHERE some_table.ASSOCIATE_ID=:p1 
AND some_table.CREDENTIAL=:p2 
AND some_table.IDENTIFIER=some_table.TRACKING_IDENTIFIER 
AND some_table.STUDENT_USER_ID=some_table.ID 
AND some_table.ID=some_table.USER_ID 
AND some_table.PROFILE_ID=some_table.ID 
# Params: some_table.ASSOCIATE_ID => 6, some_table.CREDENTIAL => 'credential'"

Basically, as you can see, the FROM part of the query is all wrong. I guess propel mistook part of the IF statement in the COUNT as table names and included them in the FROM part of the query.
Has anyone got any ideas how I could get 'round this problem or has someone even been able to get something to work?

Thanks for all your help,

Vincent

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动听の歌 2024-09-25 07:42:55

问题似乎出在 JOIN 名称上。您是否使用“join”作为字段名称???在那里尝试一个不同的名称。

Seems like the problem is with the name JOIN. Are you using "join" as a field name??? Try a different name there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文