【问题标题】:How can I join multiple tables in symfony2?如何在 symfony2 中加入多个表?
【发布时间】:2015-07-03 06:09:45
【问题描述】:

我正在做一个项目。我正在使用 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

我想要做的是加入这三个表,这样我就可以获得包含详细信息的文档类型。意味着还需要加入交易和交易细节。我不知道该怎么做。有人可以帮忙吗?

更新

我忘了说我正在使用学说查询生成器。

【问题讨论】:

    标签: php mysql symfony doctrine


    【解决方案1】:
    $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");
    

    详情请见Symfony2 / Doctrine multiple joins returns error

    【讨论】:

    • 为什么给对象的方法不存在?
    【解决方案2】:

    最好的方法可能是使用 Doctrine ORM,定义您的实体及其与注释的关系,并使用 Doctrine QueryBuilder 与您的数据进行交互。

    http://symfony.com/doc/current/book/doctrine.html

    【讨论】:

    • 我正在使用学说查询生成器。你能给我举个例子来说明我应该怎么做吗?我是新手。 :)
    • 好的,这是一条重要的信息丢失 :-) 有关示例,请参见 @kailash-sharma 答案。
    猜你喜欢
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    相关资源
    最近更新 更多