Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 6th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Doctrine2 findBy relationship object triggers string conversion error
  2. <?php
  3. // $em instanceof EntityManager, $user instanceof ModelsUser
  4. $comments = $em->getRepository('ModelsComment')
  5.     ->findBy(array('user' => $user, 'public' => true));
  6.        
  7. <?php
  8. // $em instanceof EntityManager, $user instanceof ModelsUser
  9. $comments = $em->getRepository('ModelsComment')
  10. ->findBy(array('user' => $user->getId(), 'public' => true));
  11.        
  12. <?php
  13.  
  14. namespace AppDomainRepository;
  15.  
  16. use DoctrineORMEntityRepository,
  17.     AppDomainEntityUser;
  18.  
  19. class CommentRepository extends EntityRepository
  20. {
  21.  
  22.     public function findByUser(User $user)
  23.     {
  24.         // add QueryBuilder code here
  25.     }
  26.  
  27. }
  28.        
  29. <?php
  30.  
  31. namespace AppDomainEntity;
  32.  
  33.  
  34. /**
  35.  * @Entity(repositoryClass="AppDomainRepositoryCommentRepository")
  36.  */
  37. class Comment
  38. {
  39.  
  40.     // entity definition
  41.  
  42. }