We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Unknown model or alias

Hi, and thank you for the great framework! I have a little problem here if some one can help me will be great thanks in advance.

2 Model classes: 1st one:

Module -> id | companyId | name

$this->hasMany("id", "\System\Models\Resource", "moduleId", array('alias'=>'Resource'));

2sd one:

Resource -> id | moduleId | name

$this->hasOne("id", "\System\Models\Module", "moduleId", array('alias'=>'Module'));

So when I try to get all resources for a company

  $resources = \System\Models\Resource::find( array( "Module.companyId = '" . (int)$companyId . "'" ) );

I get this error

Phalcon\Mvc\Model\Exception: Unknown model or alias 'Module' (1), when preparing:......

Am I doing something wrong or this is some bug?



58.4k

Hey man

I thinnk that a wrong, you can tried code below

 //get a resource by a company
   $module = \System\Models\Resource::findfirstByCompanyId($companyId);
   //get all compay 
   var_dump($moduel->getResource);