Buddy of mine said he saw a question I asked a long time ago. I checked it out and realized no one answered it. The answer to this question is you have to use extensions. Specifically these. https://github.com/beberlei/DoctrineExtensions/tree/master/src/Query/Mysql
Doctrine Native SQL column conflicts with another column in the mapper
-
16-07-2023 - |
Вопрос
I'm running into this problem getting a native query to map where the joined table has some columns where column name is same names from different table. For sanity this is pretty much how tables look.
Addresses
id
latitude:float
longitude:float
street:string
Properties
id:int
latitude:float
longitude:float
address_id:int
name:string
<?php
$rsm = new ResultSetMappingBuilder($this->_em);
$rsm->addRootEntityFromClassMetadata('MatrixBundle:CombinedListing', 'cl');
$rsm->addJoinedEntityFromClassMetadata('MatrixBundle:Address', 'a', 'cl', 'addresses', array('id' => 'address_id'));
$qb = $this->_em->createNativeQuery("
SELECT cl, 3959
* acos(cos(radians($lat))
* cos(radians(cl.latitude))
* cos(radians(cl.longitude) - radians($lng))
+ sin(radians($lat)) * sin(radians(cl.latitude)))
AS distance
FROM combined_listings as cl
JOIN addresses as a on a.id = cl.address_id
WHERE a.state = :state
AND a.city = :city
ORDER BY distance $order
LIMIT $offSet, $max
", $rsm);
$qb->setParameters(["state" => $state, "city" => $city]);
return $qb->getResult();
The error I get is
The column 'latitude' conflicts with another column in the mapper.
I've been searching all over for an answer, solution or workaround. I hardly ever use native queries in doctrine but DQL doesn't support acos(). Has anyone else ran into this problem?
Решение
Не связан с StackOverflow