Skip to content

Instantly share code, notes, and snippets.

@Chrysweel
Created May 14, 2013 10:55
Show Gist options
  • Save Chrysweel/5575135 to your computer and use it in GitHub Desktop.
Save Chrysweel/5575135 to your computer and use it in GitHub Desktop.
Recuperate object with DQL
/**
* @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.
@Chrysweel
Copy link
Author

With :

$Query = $em->createQuery('SELECT e FROM MyBundle:Event e JOIN e.asistencias a WHERE a.user = :user
                    ');
        $Query->setParameter('user',$user);
        return $Query->getResult();

My Entity event.php has:

/*
     *@ORM\OneToMany(targetEntity="myproject\MyBundle\Entity\Asistencia", mappedBy="event")
    */
    protected $asistencias;

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment