Search code examples
sql-order-bycriteriapropelcase-insensitive

Propel case-insensitive order by usage problem


I have been looking around for days and couldnt find anything helpfull.

my problem is; I couldn't set criteria case-insensitive ORDER (A a b B D d). Because when I try to fetch my records from DB, its not ordering properly since ascii problems (A B C a b c )

I want to set my ORDER criteria like this;

Criterias::setCriterias(Array('ORDER' => 'UPPER(name)'));

But propel doesnt let me to use UPPER in setting criterias.
So I have to set it like this;

Criterias::setCriterias(Array('ORDER' => 'name'));

I found something that may help, this function is doing what i want;

setIgnoreCase(true)

A new problem is coming with this function. If I set ORDER criteria without WHERE, it will working like a charm. But if I set 'WHERE' and 'ORDER' together, propel will giving me error.

Fatal error: Uncaught exception 'PropelException' with message 'Unable to execute SELECT statement [] [wrapped: Cannot fetch TableMap for undefined table: ]' in /usr/local/share/pear/propel/query/ModelCriteria.php:1153 Stack trace: #0 /usr/local/share/pear/propel/query/ModelCriteria.php(1019): ModelCriteria->getSelectStatement(NULL)

Thanks.


Solution

  • This is fixed in Propel 1.6.x. I pushed a few tests to prove that: https://github.com/propelorm/Propel/commit/3fc74ccffb05931ec3187b0dcff77dce732ef325