Bonjour, j'ai des enregistrements en base, les voicis:

id | created_at | user
25 |January 21, 2015, 5:58 pm | 21
26 |January 22, 2015, 12:57 pm | 21

je voudrais grâce a une requête queryBulder récupéré l'enregistrement ou la date et la plus récente 'MAX' de l'user 21, donc je fais ceci:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 $em = $this->getEntityManager();
 
        $qb = $em->createQueryBuilder();
 
        $qb->select('c','MAX(c.createdAt)')
        ->from('FrontendPanierBundle:Cart', 'c')
        ->where('c.user = :user')
        ->setParameter('user', $user);
        $query = $qb->getQuery();
 
        try {
            return $query->getSingleResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
le résultat est le suivant:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
array (size=2)
  0 => 
    object(Frontend\PanierBundle\Entity\Cart)[413]//DE OU PROVIENT CETTE OBJET
      private 'id' => int 23
      private 'cart_product' => 
        object(Doctrine\ORM\PersistentCollection)[381]
          private 'snapshot' => 
            array (size=0)
              ...
          private 'owner' => 
            &object(Frontend\PanierBundle\Entity\Cart)[413]
          private 'association' => 
            array (size=15)
              ...
          private 'em' => 
            object(Doctrine\ORM\EntityManager)[246]
              ...
          private 'backRefFieldName' => string 'cart' (length=4)
          private 'typeClass' => 
            object(Doctrine\ORM\Mapping\ClassMetadata)[334]
              ...
          private 'isDirty' => boolean false
          private 'initialized' => boolean false
          private 'coll' => 
            object(Doctrine\Common\Collections\ArrayCollection)[406]
              ...
      private 'createdAt' => string 'January 21, 2015, 5:58 pm' (length=25)
      private 'user' => 
        object(Backend\UserBundle\Entity\User)[53]
          protected 'id' => int 24
          private 'nom' => string 'Gacquere' (length=8)
          private 'prenom' => string 'Loic' (length=4)
          private 'adrfacturation' => string 'ldsds' (length=5)
          private 'codeadrf' => string 'dsds' (length=4)
          private 'villeadrf' => string 'sdds' (length=4)
          private 'adrlivraison' => string 'sd' (length=2)
          private 'codeadrl' => string 'sdds' (length=4)
          private 'villeadrl' => string 'sdsd' (length=4)
          private 'news' => boolean false
          private 'commandes' => 
            object(Doctrine\ORM\PersistentCollection)[43]
              ...
          protected 'username' => string 'loic' (length=4)
          protected 'usernameCanonical' => string 'loic' (length=4)
          protected 'email' => string 'lgacquere@free.fr' (length=17)
          protected 'emailCanonical' => string 'lgacquere@free.fr' (length=17)
          protected 'enabled' => boolean true
          protected 'salt' => string '6y5ij5exdrwg8c04go8g4o4ocw4ows8' (length=31)
          protected 'password' => string '1VgNU7JmzBBKGWQAmSuk4nawn3YvI4SLHF6+t/Rt7UAc0dJmclpD3UyXA1Na/FW6tGVLT83jV2clpUgs10VeZg==' (length=88)
          protected 'plainPassword' => null
          protected 'lastLogin' => 
            object(DateTime)[56]
              ...
          protected 'confirmationToken' => string 'jtuxmIpMtokLrMbypgJZRa8AsotoEtfPs-byoBUL_qA' (length=43)
          protected 'passwordRequestedAt' => 
            object(DateTime)[55]
              ...
          protected 'groups' => null
          protected 'locked' => boolean false
          protected 'expired' => boolean false
          protected 'expiresAt' => null
          protected 'roles' => 
            array (size=0)
              ...
          protected 'credentialsExpired' => boolean false
          protected 'credentialsExpireAt' => null
  1 => string 'January 22, 2015, 12:57 pm' (length=26)//on voir bien la date la plus récente mais de l'index 1 du tableau
je voudrais seulement récupérer l'objet ou la date est la plus récente?

Merci les amis