将SQL内部联接查询转换为Doctrine

时间:2015-06-26 23:19:15

标签: symfony doctrine-orm doctrine

嘿我转换此SQL有问题

    section .data
    dd .doAddition, .doSubtraction, .doMultiplication, .doDivision
%define MAX_OPCODES  4
    section .text

    mov ebx,[opcode]          ;ebx = next opcode
    cmp ebx,MAX_OPCODE        ;Is the opcode too large for the jump table?
    jae .error                ; yes, error
    jmp [opcodeTable + ebx*4] ; no, jump to the code that handles this opcode

.doAddition:
    ; Code to do addition here!
    jmp .done

.doSubtraction:
    ; Code to do subtraction here!
    jmp .done

.doMultiplication:
    ; Code to do multiplication here!
    jmp .done

.doDivision:
    ; Code to do division here!
    jmp .done

进入Doctrine查询构建器

SELECT DISTINCT izo_client.name
FROM izo_client
INNER JOIN izo_measurement
ON izo_client.id=izo_measurement.client_id;

错误是:

$qb = $this->_em->createQueryBuilder();
        $qb->select('u')
            ->from('AppBundle:Client', 'u')
            ->innerJoin('AppBundle:Measurement', 'm', 'WITH', 'u.id = m.client_id')
            ->distinct();

        return $qb->getQuery()->getResult();

1 个答案:

答案 0 :(得分:0)

DQL不是SQL。在DQL中,您操作对象,而不是数据库关系。使用属性而不是数据库列。

由于您的字段名为$clientsBelongsTo,因此您的查询应该更像:

$qb = $this->_em->createQueryBuilder();
$qb->select('u')
    ->from('AppBundle:Client', 'u')
    ->innerJoin('AppBundle:Measurement', 'm', 'WITH', 'u.id = m.clientsBelongsTo')
    ->distinct();