ModelsManager can't load model
I use modules and namespaces in my app. When I try get my data from db with query builder and models manager I have problem.
Let's declare namespace:
use Someapp\Somemodule\Models\Somemodel as Somemodel;
When I use standard query it's work:
Somemodel::find();
But when I use models manager I have problem ang get msg: The model 'Somemodel' could not be loaded:
$this->modelsManager->createBuilder()->from('Somemodel')->getQuery()->execute();
And now is funny moment:
$this->modelsManager->createBuilder()->from('Someapp\Somemodule\Models\Somemodel')->getQuery()->execute();
It's work :) Well... this is strange and I don't know - it's problem with models manager, namespaces in modules or what?
In this case "Somemodel" is local alias. Models Manager doesn't know about it.
Hi Riu, this is not a bug, aliases are resolved in compile time, aliases in strings cannot be resolved by PHP, so you need to write the full namespace as it is the real class name
http://php.net/manual/en/language.namespaces.importing.php
Well, I understand that, but it's very chic solution and perhaps it should be some information about that in Phalcon docs.
good, I'm going to add a note in docs, thanks