Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 robotmmparts ON ( robot.uid = robotmmparts.uidlocal AND robotmmparts.uidforeign = 4);

robotmmparts.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!



84.5k
Accepted
answer

This way:

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

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



84.5k

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!