How is it possible to add an ORDER BY columnName IS NULL DESC, columnName DESC
to a Propel query. I have the same problem as in this question but I can't seem to find a proper solution using Propel methods. Since this clause will be embedded in a rather complex query building process, I do not want to just move to plain SQL.
Asked
Active
Viewed 466 times
0

twigmac
- 1,772
- 3
- 21
- 38
-
Whats does `columnName` contain? – Samir Selia Jul 06 '17 at 08:54
-
`columnName` contains a column name or a (quoted) qualified column name, e.g. `\`tbl\`.\`col\``. In my case the column is of type `DATETIME`. It is of the same value in the first and the second occurrence. – twigmac Jul 06 '17 at 09:28
-
So you want to sort results by latest `DATETIME` first in which `NULL` values should be on top. Right? – Samir Selia Jul 06 '17 at 09:30
-
@Samir Correct. :) – twigmac Jul 06 '17 at 09:31
1 Answers
1
If you use ModelCriteria you could try:
$query = YourEntityQuery::create('e')
->withColumn('e.sortColumn IS NULL', 'isSortColumnNull')
->orderBy('isSortColumnNull', 'desc')
->orderBy('e.sortColumn', 'desc');

W0rma
- 309
- 2
- 9