findFirst condition as phql breaks app

Hi! I'm writing a cms as a one man hobby project. I started it on phalcon 1.2,, tahn had a half year pause. Now i tyr to revive my project and updated to phalcon 1.3. Earlier this code worked fine:

$trans = ArticlesTranslation::findFirst(["slug = :slug: and language = :language: and language in (select lang_code from Languages where is_active = 1)", "bind" => ["slug" => $slug, ":language:" => $language], "order" => "version desc"]);

But since 1.3 the condition is parsed as phql which doesn't support subquery, so this fails. Is there any good workaround?

It's weird that it worked fine because phalcon never supported subqueries.

Anyway, here's a workaround:


I guess it worked earlier because condition was parsed as plain sql prepaed statement, but now it's sent through the phql parser. BTW thanks for your answer, I tried that way but no luck. However it gave me few idea to play with...

edited Aug '14

Why no luck? The workaround is working for me, your code should look like this:

$trans = ArticlesTranslation::findFirst([
    "slug = :slug: and language = :language: and language in SUBQUERY('select lang_code from Languages where is_active = 1')", 
    "bind" => ["slug" => $slug, ":language:" => $language], 
    "order" => "version desc"]);

The missing piece could be that you can't use Languages as model/table in the subquery because that is a raw query, not parsed by PHQL, so you should use the actual table instead of Languages


I don't know why it didn't work, my code looked like this, i have an actual table called languages, but it told something like 'Unexpected token SUBQEURY'. Doesn't matter anyway, I made a db view where articletranslation is joined with languages, and filtered by isactive, built a simple model on that view, and used that instead: ```php $trans = vArticleTransActivelangs::findFirst(["slug = :slug: and language = :language:", "bind" => ["slug" => $slug, "language" => $language], "order" => "version desc"] ); ```