我有两个相关表。表与第二个表有一对一的关系。这是两个表的示例示例
**
registration
id | firstname | membershipfk
1 | John | 2
2 | Foo | 3
**
这是第二个表的插图
membership
id | type | discount | description
1 | Gold | xyz | xyz description
2 | Silver | xyz | xyz description
现在,我目前的挑战是使用注册表中的外键从会员表中检索会员字段。例如:Select Type, Discount and Description from Membership Entity where fk in registration entity is equal to 2
目前在我的控制器中,我正在尝试此尝试
public function getMembersAction()
{
$restresults = $this->getDoctrine()->getRepository('XXXBundle:Members')->findAll();
$data = array();
foreach ($restresults as $restresult) {
array_push($data, $this->serializeData($restresult));
}
每种协助都非常感谢
尝试以下代码
$em->getRepository('XXXBundle:Members')
->createQueryBuilder('m')
->select("m.type, m.discount, m.description")
->innerJoin("XXXBundle:Registration","r","WITH","m.id = r.membershipfk") //Here you will Join with the Registration Bundle
->where("m.id = 2")
->getQuery()
->getResults();
您需要调用娱乐方式,例如,如果您的实体设置好。
尝试以下操作:
$results = $this->getDoctrine()->getRepository('XXXBundle:Members')->findByMember($memberId);
,但是您需要首先配置您的实体