I have an User
entity with a many-to-many entity (Wish
) linked to it, I now need the top 10 wishes now using the Symfony QueryBuilder.
The problem here is that i do not have direct access to the ManyToMany Table/Entity/Repository as its automatically created and managed by Doctrine ORM.
Making a manual OneToMany, ManyToOne Entity is not really an option as it will break existing code (mostly the automatic collection population and the add / remove functions of it)
Doing a manual SQL is kinda dodgy since the table name is generated and might change some update (even if not I would prefer to keep it clean)
some code:
class User {
// .........
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Wish")
*/
private $wish;
public function __construct()
{
$this->wish = new ArrayCollection(); // with get/set/add/remove etc
}
}
class Wish {
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
// ... get set etc
}