We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Modal Alias

How can i use model aliases?

Just check docs, for example:

$result = $di->get('modelsManager')->createBuilder()
->columns('a.id,b.name,c.price')
->from(['a'=>'Models/A'])
->leftJoin('Models/B', null, 'b')
->leftJoin('Models/C', null, 'c')
->getQuery()
->execute()

Example

//App Model

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->hasMany('id_app', 'AppAdmin', 'id_app_fk_app_admin', array('alias' => 'AppAdmin'));
        $this->hasMany('id_app', 'AppCategory', 'id_app_fk_app_category', array('alias' => 'AppCategory'));
        $this->hasMany('id_app', 'AppDeveloper', 'id_app_fk_app_developer', array('alias' => 'AppDeveloper'));
        $this->hasMany('id_app', 'AppImages', 'id_app_fk_app_images', array('alias' => 'AppImages'));
        $this->hasMany('id_app', 'AppInfo', 'id_app_fk_app_info', array('alias' => 'AppInfo'));
        $this->hasMany('id_app', 'AppKeyword', 'id_app_fk_app_keyword', array('alias' => 'AppKeyword'));
        $this->hasMany('id_app', 'AppLanguage', 'id_app_fk_app_language', array('alias' => 'AppLanguage'));
        $this->hasMany('id_app', 'AppSystem', 'id_app_fk_app_system', array('alias' => 'AppSystem'));
        $this->hasMany('id_app', 'Nuvemdesktop', 'id_app_fk_nuvemload', array('alias' => 'Nuvemdesktop'));
        $this->belongsTo('id_app_license_fk', 'AppLicense', 'id_app_license', array('alias' => 'AppLicense'));
    }
//App Controller

$apps = $this->modelsManager->createBuilder()
                    ->from(['a' =>  'App'])
                    ->join('AppInfo', 'a.id_app = AppInfo.id_app_fk_app_info')
                    ->where('AppInfo.id_lang_available_fk_app_info = :id_lang:')
                    ->orderBy('AppInfo.acess_app_info DESC')
                    ->groupBy('a.id_app')
                    ->limit(50)
                    ->getQuery()
                    ->execute(['id_lang'    =>  $this->id_lang]);