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

Query without full name space

Hello everyone!

I have question about Phalcons's ORM.

Can I use a query without full namespace?

For example: SELECT a.title, b.rname, a.added, a.content, a.id FROM Multiple\Site\Models\Posts a LEFT JOIN Multiple\Site\Models\Rubrics b ON a.rid=b.rid WHERE status>0 ORDER BY a.added DESC limit 10

This Code works correct but it is too large. If I use only model's name without namespace Phalcon can't find model.

I use Phalcon 1.3.2;


edited Aug '14

Funny you posted this because I am having the same problem right now. We're supposed to be able to the registerNamespaceAlias of modelManager but it's not working for me.

In my controller I've tried:

        $this->modelsManager->registerNamespaceAlias('Posts', 'Devin\Models\Posts'); 

        $posts = $this->modelsManager->createBuilder()
            ->columns('Posts.id, Posts.body, Posts.title')
            ->orderBy('Devin\Models\Posts.created_at DESC LIMIT 10')

That errors though with: Unknown model or alias 'Posts' (1), when preparing: SELECT Posts.id, Posts.body, Posts.title FROM [Devin\Models\Posts] JOIN [Devin\Models\Users] JOIN [Devin\Models\Categories] ORDER BY Devin\Models\Posts.created_at DESC LIMIT 10

I would also like to know if this is possible. When I used full namespaces it works, and when I use aliases it doesn't.

I had same problem.

Is there any solution for this problem?