0

I read some documentations about ORM & Symfony but the English is not my mother language and maybe I miss something :) I will just make a join between reservation & spectacles I have this error :

[Semantical Error] line 0, col 70 near 'r WHERE a.id': Error: Class AppBundle\Entity\Reservation has no association named Reservation

My entities

class Reservation
{
    /**
     * @ORM\ManytoOne (targetEntity="AppBundle\Entity\Spectacles", inversedBy="id")
     * @ORM\JoinColumn(name="id", referencedColumnName="id")
     */
    private $spectacle;
}



class Spectacles
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Reservation", mappedBy="spectacle")
     * 
     */
    private $id;
}

My repository

class ReservationRepository extends \Doctrine\ORM\EntityRepository
{
     public function FindHowMunchRemains($id)
    {

         return $this->createQueryBuilder('a')
                 ->join('a.Reservation','r')
                 ->where('a.id=:id')
                 ->setParameter('id',$id)
                 ->getQuery()
                 ->getResult();


    }
}

EDIT:

I'am lost with ORM ;( I think it's my big issue with symfony ... I try to read doc but nothing it's clear maybe it's not my mother language.

I want to create this schema could you help me with the result of source code only on the KEY ?

See schema here under

SCHEMA DB

  • Can you add to the question what do you want to achieve? – Akkusativobjekt May 09 '17 at 11:29
  • 1
    It looks like you are joining `Reservation` (by doing `->join('a.Reservation','r')`) to `Reservation` (as its `ReservationRepository`). You may either want to join `a.spectacle` or do something like `a.reservation` but in `SpectacleRepository`, depending on what you're trying to do. – Jakub Matczak May 09 '17 at 11:39
  • Thanks Jakub, I try with Spectacle Repository (it's logical) but I have an error like the previous error. [Semantical Error] line 0, col 69 near 'r WHERE a.id': Error: Class AppBundle\Entity\Spectacles has no association named Reservation @Akkusativobjekt I try just to make a join to understand – Jerry Bauduin May 09 '17 at 12:41
  • By default Repository::createQueryBuilder uses the entity type associated with the repository. So the Reservation repository assumes you want to select from Reservation. To select from spectacles, add ->from('AppBundle:Spectacles','s') and use s.reservations in your leftJoin statement. And your posted Spectacle annotations are all messed up. Take the time to work through the chapter in the manual. – Cerad May 09 '17 at 12:42
  • I try but I have an error [Semantical Error line 0, col 69 near 'r, AppBundle:Spectacles': Error: Class AppBundle\Entity\Spectacles has no association named Reservation: CODE: return $this->createQueryBuilder('a') ->from('AppBundle:Spectacles','s') ->join('a.Reservation','r') ->where('a.id=:id') ->setParameter('id',$id) ->getQuery() ->getResult(); – Jerry Bauduin May 09 '17 at 12:44
  • The code you posted shows Spectacles::id having a one to many relation to Reservation. Does that make any sense to you? Again, work through the examples in the docs. And by the way, probably better to update your question as you try things and encounter errors. Reading code in comments is no fun. – Cerad May 09 '17 at 13:19

1 Answers1

0

Your relation is not valid, should be:

class Reservation
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Spectacle", inversedBy="reservations")
     */
    private $spectacle;
}



class Spectacle
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Reservation", mappedBy="spectacle")
     */
    private $reservations;
}

In the other hand your query is not valid. Exactly what do you want to get?

rafrsr
  • 1,940
  • 3
  • 15
  • 31