本文介绍了如何在symfony2中加入多个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开展一个项目。我使用symfony2与XAMPP与PHP版本5.5.19。我有三张桌子有关系..以下是表格:
table_name:transaction_tbl
- transaction_id
-filename
-filepath
-sender
-doctype_id
table_name:doctype_tbl
-doctype_id
- doctype
-name
-description
table_name:transaction_details
- details_id
-ref_numbers
-amount
-transaction_id
我要做的是加入三个表所以我可以得到它的细节的doctype。意义也需要加入交易和交易细节。我不知道该怎么做有人可以帮忙吗?
更新
我忘了说我正在使用doctrine查询构建器。
解决方案
$ qb-> select('DISTINCT m'
- > from('MessageBundle:AssignmentUser','au')
- > innerJoin('au.assignment','a','WITH','a.status = )')
- > innerJoin('au.user','u')
- > innerJoin('a.message','m')
- >其中( 'u.id =(:user_id)')
- > setParameter('assigned','assigned')
- > setParameter('user_id',$ yourSpecificUserId)
- > ; orderBy(m.createdAt,desc);
请参阅。
I am working on a project. I am using symfony2 with XAMPP with PHP version of 5.5.19. I have three tables that have relationship ..
Here are the tables :
table_name : transaction_tbl
- transaction_id
-filename
-filepath
-sender
-doctype_id
table_name : doctype_tbl
-doctype_id
- doctype
-name
-description
table_name : transaction_details
- details_id
-ref_numbers
-amount
-transaction_id
what I want to do is to join the three tables so I can get the doctype with its details. Meaning need to join also the transaction and the transaction details. I don't know how to do it. Can somebody help ?
UPDATE
I forgot to say that I am using doctrine query builder.
解决方案
$qb->select('DISTINCT m')
->from('MessageBundle:AssignmentUser', 'au')
->innerJoin('au.assignment', 'a', 'WITH', 'a.status = (:assigned)')
->innerJoin('au.user', 'u')
->innerJoin('a.message', 'm')
->where('u.id = (:user_id)')
->setParameter('assigned', 'assigned')
->setParameter('user_id', $yourSpecificUserId)
->orderBy("m.createdAt", "desc");
See Symfony2 / Doctrine multiple joins returns error for details.
这篇关于如何在symfony2中加入多个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!