We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Many to Many Relation query

Hey guys! I have a Many-to-many relation that works as I want to, everything fine. My Question now: I want do a query like

SELECT * FROM robot INNER JOIN robot_mm_parts ON ( robot.uid = robot_mm_parts.uid_local AND robot_mm_parts.uid_foreign = 4);

robot_mm_parts.uid_foreign is the uid of the RobotParts table. So in other word: I want all robots with a certain robot part, how can I realize this with "Robots->find()"?

Thanks for helping me!


This way:

$robots = $this->modelsManager->createBuilder()
    ->join('RobotsParts', 'Robots.uid = RobotsParts.uid_local AND RobotsParts.uid_foreign = 4')

I think I have to join the MM Table right? ;)


I can't understand your question

Sorry for my late response, I got it to work with your example, I just added my relation table "robotmmparts" to that query and it works Thx!