Created
May 14, 2013 10:55
-
-
Save Chrysweel/5575135 to your computer and use it in GitHub Desktop.
Recuperate object with DQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @ORM\Entity | |
* @ORM\Table(name="asistencia") | |
* @ORM\Entity(repositoryClass="sdfs\sdfsBundle\EntityManager\AsistenciaRepository") | |
*/ | |
class Asist{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
/** | |
* @ORM\ManyToOne(targetEntity="myproject\MyBundle\Entity\User", inversedBy="asistencias") | |
* @ORM\JoinColumn(name="usuario_id", referencedColumnName="id") | |
*/ | |
protected $user; | |
/** | |
* @ORM\ManyToOne(targetEntity="myproject\MyBundle\Entity\Evento", inversedBy="asistencias") | |
* @ORM\JoinColumn(name="evento_id", referencedColumnName="id") | |
*/ | |
protected $event; | |
In my repository: | |
public function myAsist($user){ | |
$em = $this->getEntityManager(); | |
$Query = $em->createQuery('SELECT a.event FROM MyBundle:Asist a | |
WHERE a.user = :user | |
'); | |
$Query->setParameter('user',$user); | |
return $Query->getResult(); | |
} | |
I get the following error: | |
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 9 near 'event FROM MyBundle:Asist': Error: Invalid PathExpression. Must be a StateFieldPathExpression.") in MyBundle:XXX:XXX.html.twig at line 108. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With :
My Entity event.php has:
I get the error:
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 53 near 'a WHERE a.user': Error: Class myproject\MyBundle\Entity\Event has no association named asistencias") in MyBundle:xxx:XXX.html.twig at line 108.