Select Distinct in Doctrine and Symfony

0

Hi, I have a photo album creation table. My code makes 1 insert for each image added in the photo album. I have a grid for displaying the albums for the user to view. I want to make a distinct of duplicate albums.

I have this type of code:

      $select = Doctrine_Query::create()
                                ->select('DISTINCT s.idAlbum')
                                ->addSelect('s.imagens_data, s.publicar')
                                ->from('tbimagens s')->getSqlQuery();
      print_r($select);
      die;

This is my result in Sql:

 SELECT DISTINCT 
   t.id AS t__id, 
   t.idalbum AS t__idalbum, 
   t.imagens_data AS t__imagens_data, 
   t.publicar AS t__publicar 
 FROM tbimagens t

Have you seen that select carries the Id of the table? This Id is making me unable to make the correct select because all Ids are already naturally distinct.

Can anyone help me with this query? I am using symfony 1.4 and doctrine 1.2

    
asked by anonymous 10.09.2015 / 14:25

1 answer

0
$select = Doctrine_Query::create()
  ->from('tbimagens s')
  ->select('DISTINCT s.id_album')
  ->addSelect('s.imagens_data, s.publicar')
  ->getSqlQuery();

Dude tries to see if you're not passing a wrong parameter, in this case the foreign key to the album. And also the order as you create the select, but really it can not put in your select the id of the table.

Another solution would be to put a unique in the foreign key.

    
01.02.2016 / 14:24