我编写了一个简单的 symfony Controller ,其中有两个表,分别称为 specialtyarea 和 physician。
这是表的基本结构
specialtyarea
-----------------
id | name |
-----------------
1 | dentist |
2 | physician |
Physician 表与specialtyarea
相关,如下所示:
Physician
--------------------
id | name | specfk |
--------------------
1 | John | 1 |
2 | Doe | 2 |
3 | Ann | 2 |
我正在尝试获取专业领域为 2 的所有医生
这是我的代码片段
public function getAllPhysicianAction($specId)
{
$id = $this->getDoctrine()->getRepository('Bundle:SpecArea')
->find($specId); //assuming that this returns all the id from the specialty table
$allPhysician = $id->getPhysician()->... //kind of lost here
}
如何使用专业 Id 从医生表中检索所有记录?
最佳答案
我相信您可以在您的医生资料库上调用 findBy。
/**
* @Route("/physicians/{specId}", name="getAllPhysician")
*/
public function getAllPhysicianAction($specId)
{
$allPhysician = $this->getDoctrine()
//call the repository of your physician table
->getRepository('Bundle:physician')
->findBy(['specfk' => $specId]);
var_dump($allPhysician);
}
关于php - 如何使用 Join 和 where 子句从多个表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43963396/