Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Namespace in query

Hi guys. Is there anyway to register namespaces to prevent having to use full namespace in a query on a model?

$api_method = Apiv2Method::query()
            ->join("Core\Models\Apiv2AuthType", "a.id = Core\Models\Apiv2Method.auth_type_id" , "a")
            ->where("Core\Models\Apiv2Method.method_name = :method_name:")
            ->andWhere("Core\Models\Apiv2Method.active = true AND a.active = true")
            ->bind(["method_name" => $this->methodName])
            ->execute();

Maybe look at using the ModelsManager and the addFrom() method instead? You can set an alias in there. You'll still have to reference the namespace once, but thereafter can just reference the alias.



116.1k
Accepted
answer
edited Jun '20

Are you running v3.4 or v4? v3.4 has registerNamespaceAlias(): https://docs.phalcon.io/3.4/en/api/phalcon_mvc_model_manager#methods, but that was removed in v4 and I'm not sure if that functionality was replaced anywhere.