Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在CakePHP3中编写sql多表联接查询?_Sql_Cakephp 3.0_Jointable - Fatal编程技术网

如何在CakePHP3中编写sql多表联接查询?

如何在CakePHP3中编写sql多表联接查询?,sql,cakephp-3.0,jointable,Sql,Cakephp 3.0,Jointable,我在Sql中有这个查询,提供了必修课程路径,但我无法在Cakephp 3中实现,尽管我在Cakephp模型中创建了这些表之间的关系 SELECT c.course_path FROM courses c JOIN modules m ON c.id = m.course_id JOIN topics t ON m.id = t.module_id WHERE t.topic_name = 'test_topic'. 非常感谢@ndm。这个链接解决了我的问题:)还有一个问题-

我在Sql中有这个查询,提供了必修课程路径,但我无法在Cakephp 3中实现,尽管我在Cakephp模型中创建了这些表之间的关系

  SELECT c.course_path
  FROM courses c
  JOIN modules m ON c.id = m.course_id
  JOIN topics t ON m.id = t.module_id
  WHERE t.topic_name = 'test_topic'.

非常感谢@ndm。这个链接解决了我的问题:)还有一个问题-我如何在查询中传递变量而不是固定值-$This->Contacts->find()->contain('Users')->matching('Users',function(\Cake\ORM\Query$q){return$q->where(['Users.id'=>1]);});非常感谢@ndm。这个链接解决了我的问题:)还有一个问题-我如何在查询中传递变量而不是固定值-$This->Contacts->find()->contain('Users')->matching('Users',function(\Cake\ORM\Query$q){return$q->where(['Users.id'=>1]);});