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

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])

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.

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.