I have entities Offer and Area and here one Offer can have many Areas and one Area belong to many Offers:
Offer entity:
/**
* @ORM\ManyToMany(targetEntity="Area")
* @ORM\JoinTable(name="relationship_offer_areas",
* joinColumns={@ORM\JoinColumn(name="offer_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="area_id", referencedColumnName="id")}
* )
*/
private $areas;
Now I am trying to get Offers by Area using DQL (not query builder!):
$query = 'SELECT o FROM IndexBundle:Offer o '.
'LEFT JOIN IndexBundle:Area a '.
'WHERE a = :area '.
'ORDER BY o.startDate ASC';
Here :area is Area entity object. Unfortunately it is not working as expected. I get all offer rows with all the areas.
Any ideas what am I missing? Working with Entities in query language really twist my mind. Thank you!
It doesn't know how to use the
JOINon the fly. Use the properties of your entities for joining. It's is just like you do aLEFT JOINwithin SQL as you refer to a column where you want additional data from. As you specify in theONof the join.