We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Multilanguage (i18n) database/models

Hello guys, here is sample database/table organization i want to use for i18n application:

table news, columns: id, is_active, created_at

table news_i18n, columns: foreign_key, language, title, content

My issue at the moment is with models and that i have to create a model for the News_i18n table in order to use ORM or query builder. Is there a way to avoid this? My idea was to make a function which joins the two tables with phql, but even that requires me to have a model for the news_i18n table.

Any suggestions or sample public code will be greatly appreciated.

edited Oct '15

$this->DB = \Phalcon\Di::getDefault()->get('db');

$sth = $this->DB->prepare("
            SELECT * FROM `users`

            LEFT JOIN bla bla on bla bla bla

            WHERE language = :page_lang and t1.page_id = :page_id AND t1.type_id = :type"

        $sth->bindValue(':page_lang', $lang_id, \PDO::PARAM_INT);
        $sth->bindValue(':page_id', $page_id , \PDO::PARAM_INT);
        $sth->bindValue(':type', $type , \PDO::PARAM_INT);

        //return $sth->fetch() -> returns with LIMIT 1 or false
        return $sth->fetchAll(); /returns array of all or empty array

I always go for this kind a solutions at the beggning ( when there is a lof of custom logic ), cuz i dont wanna waste days, for a simple query

edited Oct '15

Hey Izo, thanks for your answer. Ill mark it as accepted since it does the job.

Just gonna leave this here in case anyone else is having doubts on what to use.

I tested few other methods and in the end i decided to use 2 models News and NewsI18n and get info with the query builder/model relations. This will be my temporary solution, while Phalcon Team is working on EagerLoading.