I have an entity called Reservations that has two relationships with other tables.
reservation.orm.yml
oneToMany:
emails:
targetEntity: Acme\EmailBundle\Entity\Email
mappedBy: reservation
oneToMany:
texts:
targetEntity: Acme\TextBundle\Entity\Text
mappedBy: reservation
email.orm.yml
manyToOne:
reservation:
targetEntity: Acme\ReservationBundle\Entity\Reservation
inversedBy: emails
joinColumn:
name: reservation_id
referencedColumnName: id
text.orm.yml
manyToOne:
reservation:
targetEntity: Acme\ReservationBundle\Entity\Reservation
inversedBy: texts
joinColumn:
name: reservation_id
referencedColumnName: id
Using this code, I have access to the texts by doing
$reservation->getTexts();
However, when I do
$reservation->getEmails();
Symfony returns NULL, even though in my database, the email has a reservation ID of the reservation I'm trying to get the emails of. So, from what it seems like, it creates the email and sets the reservation, but for some reason I'm unable to get the emails for those reservations, in PHP or Twig.
I think this is because I didn't define my relationships correctly, though they are basically cookie-cutter many-to-one. The order that they are placed is screwing it up. In my reserations PHP, I do create an array collection to store emails just like texts. Don't know what's going on....
Try this for the reservations yml file..
oneToMany:
oneToMany:
texts:
targetEntity: Acme\TextBundle\Entity\Text
mappedBy: reservation
emails:
targetEntity: Acme\EmailBundle\Entity\Email
mappedBy: reservation