Hi guys,
I'm trying to join
two tables by using the createBuilder
, but I keep getting this error:
Unknown model or alias 'ErrorLogHistory' (11), when preparing: SELECT * FROM [m:ErrorLogHistory], [m:ErrorLog] INNER JOIN [m:ErrorLog] ON ErrorLogHistory.log = m:ErrorLog.id
QueryBuilder code is as follows:
<?php
$res = $this->modelsManager->createBuilder()
->addFrom("m:ErrorLogHistory")
->addFrom("m:ErrorLog")
->columns("*")
->innerJoin("m:ErrorLog", "m:ErrorLogHistory.log = m:ErrorLog.id")
->getQuery()
->execute();
Services:
<?php
$di->setShared('modelsManager', function () {
$modelsManager = new ModelManager();
$modelsManager->registerNamespaceAlias("m", "\\Rugbrod\TrackPHP\API\Models");
return $modelsManager;
});
Relationship: ErrorLog:
<?php
public function initialize()
{
$this->hasMany('id', 'Rugbrod\TrackPHP\API\Models\ErrorLogHistory', 'log', ['alias' => 'ErrorLogHistory']);
}
ErrorLogHistory:
<?php
public function initialize()
{
$this->belongsTo('log', __NAMESPACE__.'\\ErrorLog', 'id', ['alias' => 'ErrorLog']);
}
Phalcon version : 3.3.1
OS: Ubuntu 16.04
PHP Version: 7.1.13
Any idea please?