N
N
NubasLol2018-07-22 19:34:12
symfony
NubasLol, 2018-07-22 19:34:12

Doctrine why doesn't dql work, what am I doing wrong?

$query = $entityManager->createQuery(
            'SELECT MAX(employee.salary) FROM
                AppBundle:Employee employee
                JOIN  AppBundle:Department department
                WHERE department.id = :id'
        )->setParameter('id', $department->getId());

        $result = $query->getSingleScalarResult();

for some reason it ignores the department.id = :id comparison, and always returns the result .
$department->getId() which is equal to 32 should only get the result, because it has an employee and nowhere else. How to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2018-07-23
@NubasLol

You're asking incorrectly. It should look something like this (I assume you have a @ManyToOne relationship configured between Employee and Department):

SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
JOIN employee.department department
WHERE department.id = :id

Can be done without connections if you use the IDENTITY DQL function:
SELECT MAX(employee.salary)
FROM AppBundle:Employee employee
WHERE IDENTITY(employee.department) = :id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question