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

Two Namespaces Not Working

I have the following query, where the joined table is in a different namespace. I get an error message that "Base table or view not found" for the second namespace (App\Models\Site), and its table is referenced as if it is in the first namepace (App\Models\Common): "Table 'common.owner_assessment' doesn't exist".

Is the problem that Phalcon does not support this, or am I doing something wrong?

                    $data = $model->getModelsManager()->createBuilder()
                        ->addFrom('App\Models\Common\Assessment', 'a')
                        ->join('App\Models\Site\OwnerAssessment', NULL, 'oa')
                        ->where("a.site_id = :sid: AND oa.person_id=17")
                        ->orderBy('a.name')
                        ->getQuery()
                        ->execute(['sid' => $id])
                        ->toArray();

I think the second namespace is nowhere registered in your current namespace.

Try incorporating the following;

$modelsManager->registerNamespaceAlias('Site', 'App\Models\Site');
Site:OwnerAssessment

Thank you, but I think it is already done, in the setup:

        $loader->registerNamespaces([
            'Phang'             => __DIR__,
            'Aws'               => dirname(__DIR__) . '/vendor/aws/aws-sdk-php/src',
            'App\Controllers'   => $app->settings['phalcon']['controllersDir'],
            'App\Models'        => $app->settings['phalcon']['modelsDir'],
            'App\Models\Site'   => $app->settings['phalcon']['modelsDir'] . 'site/',
            'App\Models\Common' => $app->settings['phalcon']['modelsDir'] . 'common/',
            'App\Components'    => $app->settings['phalcon']['componentsDir']
        ]);

I am not having any problems with either of the namespaces on their own, only within joins.

I am using the latest (3.2) version of Phalcon available by brew install, on Mac OS X.

edited Sep '17

Frankly, if this does not work, Houston we have a problem with Loader and ORM.

Mac OS X? Hmmm, what are actual names of your dirs and files? Is your Mac using default CI filesystem or perhaps it is tuned to be CS?

Table 'common.owner_assessment' doesn't exist This means taht TABLE not MODEL doesn't exist. Are you sure there is such table in database?

edited Oct '17

Yes. Single namespace queries against either table work fine. It is the join that does not.

Table 'common.owner_assessment' doesn't exist This means taht TABLE not MODEL doesn't exist. Are you sure there is such table in database?

Straight, out-of-the-box Mac OS X, Sierra.

Paths are somethling like /Users/dqj/dev/project/backend/controllers (models, etc).

It works fine for many other queries, using single namespaces, for both namespaces individually.

Frankly, if this does not work, Houston we have a problem with Loader and ORM.

Mac OS X? Hmmm, what are actual names of your dirs and files? Is your Mac using default CI filesystem or perhaps it is tuned to be CS?