Bonjour MehrezLabidi, merci pour ton aide 
J'ai donc essayer ta méthode, voici l'ErrorException qui en découle :
Notice: Trying to get property 'skills' of non-object
sur la ligne : $jointure->skills->toArray();
Je pense que vous avez besoin de voir mes entités afin de mieux comprendre, les voici :
Entité Jointure (que j'ai un peu raccourci):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/**
* @ORM\Entity(repositoryClass="App\Repository\JointureRepository")
*/
class Jointure
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Skill", mappedBy="jointure")
*/
private $skills;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Answer", mappedBy="jointure")
*/
private $answers;
public function __construct()
{
$this->skills = new ArrayCollection();
$this->answers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Skill[]
*/
public function getSkills(): Collection
{
return $this->skills;
}
public function addSkill(Skill $skill): self
{
if (!$this->skills->contains($skill)) {
$this->skills[] = $skill;
$skill->setJointure($this);
}
return $this;
}
public function removeSkill(Skill $skill): self
{
if ($this->skills->contains($skill)) {
$this->skills->removeElement($skill);
// set the owning side to null (unless already changed)
if ($skill->getJointure() === $this) {
$skill->setJointure(null);
}
}
return $this;
}
/**
* @return Collection|Answer[]
*/
public function getAnswers(): Collection
{
return $this->answers;
}
} |
Entité Skill :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
/**
* @ORM\Entity(repositoryClass="App\Repository\SkillRepository")
*/
class Skill
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $label;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Jointure", inversedBy="skills")
* @ORM\JoinColumn(nullable=false)
*/
private $jointure;
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getJointure(): ?Jointure
{
return $this->jointure;
}
public function setJointure(?Jointure $jointure): self
{
$this->jointure = $jointure;
return $this;
}
} |
Entité Answer :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
/**
* @ORM\Entity(repositoryClass="App\Repository\AnswerRepository")
*/
class Answer
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $UserEmail;
/**
* @ORM\Column(type="date")
*/
private $Date;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Jointure", inversedBy="answers")
* @ORM\JoinColumn(nullable=false)
*/
private $jointure;
public function getId(): ?int
{
return $this->id;
}
public function getUserEmail(): ?string
{
return $this->UserEmail;
}
public function setUserEmail(string $UserEmail): self
{
$this->UserEmail = $UserEmail;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->Date;
}
public function setDate(\DateTimeInterface $Date): self
{
$this->Date = $Date;
return $this;
}
public function getJointure(): ?jointure
{
return $this->jointure;
}
public function setJointure(?jointure $jointure): self
{
$this->jointure = $jointure;
return $this;
}
} |
Malgrès avoir créer une relation ManyToOne depuis ( Skill et Answer ) vers mon entité Jointure , voici à quoi correspond ma table Jointure ( absence de answer_id et skill_id ) mais je pense que ça ne devrait pas être le problème :

Par ailleurs , si je fais
$skills = $repository->find(1)->getSkills();
je récupère bien dans le foreach mes skills dans Twig mais je voulais savoir comment TOUS les récupérer..
Partager