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.

Unknown model or alias with namespaces module app

Hi guys,

currently facing a problem when executing this statement:

    $skills = \Namespace\Models\Employeeskill::query()
            ->leftJoin('\Namespace\Models\Technology', '\Namespace\Models\Employeeskill.technologyId = \Namespace\Models\')
            ->where('\Namespace\Models\Employeeskill.employeeId = :userid:', ['userid' => $this->session->get('userid')])
            ->orderBy('\Namespace\Models\ DESC')

I am getting this error:

Unknown model or alias 'Namespace\Models\Technology' (11), when preparing: SELECT \Namespace\Models\Employeeskill.level, \Namespace\Models\ FROM [Namespace\Models\Employeeskill] LEFT JOIN [\Namespace\Models\Technology] ON \Namespace\Models\Employeeskill.technologyId = \Namespace\Models\ WHERE \Namespace\Models\Employeeskill.employeeId = :userid: ORDER BY \Namespace\Models\ DESC

Namespaces are correct and were working before, except for this statement.

Any ideas?


I know that seems to be a quick answer, but....

  • Have you tried removing the leading backslashes \Namespace\Models\ModelName to Namespace\Models\ModelName?
  • Are you sure that all the Namespaces and Model names are written correctly?
edited Jun '17

Yeah I tried removing the leading backslashes, won't work either.

And I tripled checked if everything is correctly written, it is.

Also I recognized that my model relationships aren't working too...... setup some hasMany etc. doesn't work -.-

Model Location:

    $this->belongsTo('id', '\Namespace\Models\Employee', 'location_id');

Model Employee

    $this->hasMany('location_id', '\Namespace\Models\Location', 'id');


    namespace Namespace\Modules\Frontend\Controllers;

    $user = \Namespace\Models\Employee::findFirst(array(
            'alias = :user:',
            'bind' => ['user' => (is_null($username)) ? $this->session->get('username') : $username]

    $user->location->name; // NULL
    $user-getLocation(); // return als NULL


I am using now pure SQL Statements with modelsManager->createQuery.

Works like a charm

edited Dec '18

I know it's old thread, but I will post an answer how to do this (I found this thread when I got same problem). My models have namespace app\models and this is how I do inner join:

  // SELECT * FROM AdSenseAccountChannel INNER JOIN ApiKey ON = AdSenseAccountChannel.apiKeyId WHERE ApiKey.value = $apiKeyValue
  return self::query()
  ->innerJoin("app\models\ApiKey", "app\models\ = app\models\AdSenseAccountChannel.apiKeyId")
  ->andWhere('app\models\ApiKey.value = :apiKeyValue:', ['apiKeyValue' => $apiKeyValue])

Or shorter form:

return self::query()
  ->innerJoin("app\models\ApiKey", " = app\models\AdSenseAccountChannel.apiKeyId", "ApiKey")
  ->andWhere('ApiKey.value = :apiKeyValue:', ['apiKeyValue' => $apiKeyValue])

Hope it helps someone :)!