Phalcon model - if statement problem

My oryginal query is

SELECT Parts.partid FROM Parts LEFT JOIN Pages ON(Pages.datasource_id=Parts.partid AND Pages.page_language=Parts.lang ) LEFT JOIN PartsModyfication ON(PartsModyfication.id=Parts.id) WHERE Parts.sparte LIKE :sparte: AND Parts.lang =:lang: AND IF(PartsModyfication.partsel <> "" OR PartsModyfication.partsel IS NOT NULL,PartsModyfication.partsel,Parts.partsel) like :partsel: ORDER BY dateupdate DESC

When I run it via executeQuery

$partes = $this->modelsManager->executeQuery( $sQuery, $bind );

Phalcon produce query without table aliases in IF statement

SELECT parts.partid AS partid FROM parts LEFT JOIN pages ON (pages.datasource_id = parts.partid AND pages.page_language = parts.lang) LEFT JOIN parts_modyfication ON (parts_modyfication.id = parts.id) WHERE parts.sparte LIKE :sparte AND parts.lang = :lang AND IF(partsel <> '' OR partsel IS NOT NULL, partsel, partsel) LIKE :partsel ORDER BY dateupdate DESC

It coses sql partsel ambiguous partsel column name problem.

Is there any fix for that?

What version of Phalcon are you using? Are you using 2.0.4?

No 1.3.0. I found the solution. Rescent query wasn't full because I thought that it doesn't matter. The full version of that query is with longer SELECT section

SELECT Parts.partid Parts.partid, Parts.ean, IF(Parts.dateupdate IS NULL, Parts.datecreate, Parts.dateupdate) dateupdate,IF(PartsModyfication.partsel !="" OR PartsModyfication.partsel IS NOT NULL,PartsModyfication.partsel,Parts.partsel) partsel FROM Parts LEFT JOIN Pages ON(Pages.datasource_id=Parts.partid AND Pages.page_language=Parts.lang ) LEFT JOIN PartsModyfication ON(PartsModyfication.id=Parts.id) WHERE Parts.sparte LIKE :sparte: AND Parts.lang =:lang: AND IF(PartsModyfication.partsel <> "" OR PartsModyfication.partsel IS NOT NULL,PartsModyfication.partsel,Parts.partsel) like :partsel: ORDER BY dateupdate DESC

And alias 'partsel' in select section causes that problem

It is wire but if you change 'partsel' alias in SELECT section ie. on 'partsel2' or even 'Partsel' (first letter upercase) the problem disappear and phalcon DO add table aliases in WHERE section.

I think that is some kind of bug.

I don't check if the same happend in Phalcon 2.0.4

Please check if it happens in 2.0.4 as 1.3.x is no longer supported