I've been working with Phalcon and slowly getting to grips with it. However, I've stumbled across an issues and it's got me stumped. I'm hoping that someone else can provide some assistance.
I have two tables in the DB that are related as a one-to-many. clients->sites. These are the two definitions of the models in Phalcon:
#File: CrmClients.php
namespace CRM\Models;
use Phalcon\Mvc\Model\Resultset\Simple as Resultset;
class CrmClients extends \Phalcon\Mvc\Model
{
public id;
public function initialize()
{
$this->hasMany("id", "CRM\Models\CrmSites", "client_id", array("alias" => "Sites"));
}
}
#File: CrmSites.php
namespace CRM\Models;
class CrmSites extends \Phalcon\Mvc\Model
{
public id;
public client_id;
public function initialize()
{
$this->belongsTo("client_id", "CRM\Models\CrmClients", "id", array("foreignKey" => true, "alias" => "Clients"));
}
}
Then in the controller I have:
$profile = Clients::findFirstById($id);
$sites = $profile->Sites;
When I run this I end up with the following error:
Notice: Access to undefined property CRM\Models\CrmClients::Sites in \html\apps\crm\controllers\ClientsController.php on line 51
I'm at a loss as to what I'm doing wrong here, and any help would be greatly appreciated.
If you have any questions, or need any clarification, please just ask.
Thanks for your help in advance.