iizno iizno - 4 months ago 36
PHP Question

How can I solve this : The column 'created_at' conflicts with another column in the mapper

I'm currently working on a little project with Symfony2.

I'm trying to get all entries from one day (today by default) from a table.

I first tried with

DAY()
in my doctrine query builder but that doesn't work, so I use now a native sql query in my entity repository:

$em = $this->getEntityManager();

$rsm = new ResultSetMappingBuilder($em);
$rsm->addRootEntityFromClassMetadata('Teacup\CompareBundle\Entity\Log', 'l');
$rsm->addJoinedEntityFromClassMetadata('Teacup\CompareBundle\Entity\Frame',
'f',
'l',
'frame',
array('id' => 'frame_id'));

$query = $em->createNativeQuery('SELECT l.id, l.severity,
l.details, l.created_at, f.url
FROM log l
INNER JOIN frame f ON l.frame_id = f.id
WHERE DAY(l.created_at) = :day', $rsm);


But i get this error:

The column 'created_at' conflicts with another column in the mapper.


and I don't find how to solved it. I'm pretty sure it's nothing but, I just keep trying without any success. Can someone help me?

Answer

Why don't you use the DBAL layer?

$day = date('d');

$dbal = $this->getDoctrine()->getConnection('default');
$stmt = 'SELECT l.id, l.severity, l.details, l.created_at, f.url FROM log l 
         INNER JOIN frame f ON l.frame_id = f.id 
         WHERE DAY(l.created_at) = :day';

$data = $dbal->fetchAssoc( $stmt , array( 'day' => $day ) );
Comments