Answer the question
In order to leave comments, you need to log in
How to select a ManyToMany field in Symfony?
Symphony 5.2
/**
* @ORM\Entity(repositoryClass=VacancyRepository::class)
* @ORM\Table(name="vacancies")
*/
class Vacancy
{
/**
* @ORM\ManyToMany(targetEntity=Skill::class, inversedBy="vacancies")
*/
private $skill;
}
...
/**
* @ORM\Entity(repositoryClass=SkillsRepository::class)
* @ORM\Table(name="skills")
*/
class Skill
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=50)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $url;
/**
* @ORM\ManyToMany(targetEntity=Vacancy::class, mappedBy="skill")
*/
private $vacancies;
public function __construct()
{
$this->vacancies = new ArrayCollection();
}
}
$vacanciesQueryBuilder = $entityManager->getConnection()
->createQueryBuilder()
->select('v.*, v.english_level')
->from($entityManager->getClassMetadata(Vacancy::class)->getTableName(), 'v')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question