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

Getting related of related

I have a setup almost identical to the exmaple under: https://docs.phalcon.io/en/latest/reference/models.html#defining-relationships, but instead I am using "Companies", "CompanyEmployees", "Employees" where an Employee can be related only to one Company.

How can I get all employees in a company using a magic getter in the Companies model? I can only retrieve the CompanyEmployees records, but not the Employees.It is the same as the example in the ref above, where $robot->getRobotsParts(); would work but $robot->getParts(); does not.

Is it supposed to work that way at all or am I missing something else in setting up the relationships?

Could you please post some code that explain better the situation?

edited Jul '15

Can u provide more details about your models and relations? Just check:

  1. if in Companies u have hasManyToMany relation ship

  2. Did u have models named "Companies", "CompanyEmployees" & "Employees"

So if u have that, u can do something like :

$company = Model\Company::findFirst();
$company->getEmployees();

// OR
$company->Employees  // depends of alias if u have it