开发者

IF statement in Propel select criteria

开发者 https://www.devze.com 2023-01-14 22:36 出处:网络
I am trying to incorporate an IF statement into my propel criteria. This i开发者_StackOverflow社区s the how I build up my criteria:

I am trying to incorporate an IF statement into my propel criteria. This i开发者_StackOverflow社区s 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消