【问题标题】:Join two entities in symfony2 using doctrine2使用教义2加入symfony2中的两个实体
【发布时间】:2012-10-14 09:55:49
【问题描述】:

有两个实体。 票证设备

device orm中有

<one-to-many target-entity="Ticket" mapped-by="Device" field="ticket"/>
<many-to-one field="category" target-entity="Category"/>

票证

<many-to-one field="device"  target-entity="Device"/>

我想实现一个过滤器,用户可以在其中按设备类别过滤工单。我怎样才能做到这一点?我试过了

$qb->select(array('t', 'd'))
        ->from('MyBundle:Ticket', 't')
        ->innerJoin('t.device', 'd')
        ->where("t.category.name = 'Cashbox'");;

但这给了我一个错误

[Syntax Error] line 0, col 88: Error: Expected =, <, <=, <>, >, >=, !=, got '.'

【问题讨论】:

    标签: symfony doctrine-orm dql


    【解决方案1】:
    ->where("t.category.name = 'Cashbox'");;
    

    不正确。您必须加入类别表:

    $qb
        ->select(array('t', 'd'))
        ->from('MyBundle:Ticket', 't')
        ->innerJoin('t.device', 'd')
        ->innerJoin('d.category', 'c')
        ->where("c.name = 'Cashbox'");
    

    【讨论】:

    • 这也不起作用,[Semantical Error] line 0, col 94 near 'c WHERE c.name': Error: Class Ticket has no association named category
    • 哦,是具有类别关系的设备。更新
    猜你喜欢
    • 2015-02-01
    • 1970-01-01
    • 2017-08-02
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    相关资源
    最近更新 更多