Skill: Fix entity relation between Skill and SkillRelUser

pull/5964/head
Angel Fernando Quiroz Campos 9 months ago
parent 6f30ab709b
commit 817d912b24
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 22
      src/CoreBundle/Entity/Skill.php
  2. 10
      src/CoreBundle/Entity/SkillRelUser.php

@ -287,6 +287,28 @@ class Skill implements Stringable, Translatable
return $this->issuedSkills;
}
public function addIssuedSkill(SkillRelUser $issuedSkill): static
{
if (!$this->issuedSkills->contains($issuedSkill)) {
$this->issuedSkills->add($issuedSkill);
$issuedSkill->setSkill($this);
}
return $this;
}
public function removeIssuedSkill(SkillRelUser $issuedSkill): static
{
if ($this->issuedSkills->removeElement($issuedSkill)) {
// set the owning side to null (unless already changed)
if ($issuedSkill->getSkill() === $this) {
$issuedSkill->setSkill(null);
}
}
return $this;
}
/**
* @return Collection<int, SkillRelItem>
*/

@ -50,20 +50,20 @@ class SkillRelUser
#[ORM\GeneratedValue]
protected ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class, cascade: ['persist'], inversedBy: 'achievedSkills')]
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'achievedSkills')]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
protected User $user;
#[Groups(['skill_rel_user:read'])]
#[ORM\ManyToOne(targetEntity: Skill::class, cascade: ['persist'], inversedBy: 'issuedSkills')]
#[ORM\ManyToOne(targetEntity: Skill::class, inversedBy: 'issuedSkills')]
#[ORM\JoinColumn(name: 'skill_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
protected ?Skill $skill = null;
#[ORM\ManyToOne(targetEntity: Course::class, cascade: ['persist'], inversedBy: 'issuedSkills')]
#[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'issuedSkills')]
#[ORM\JoinColumn(name: 'course_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
protected ?Course $course = null;
#[ORM\ManyToOne(targetEntity: Session::class, cascade: ['persist'], inversedBy: 'issuedSkills')]
#[ORM\ManyToOne(targetEntity: Session::class, inversedBy: 'issuedSkills')]
#[ORM\JoinColumn(name: 'session_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
protected ?Session $session = null;
@ -111,7 +111,7 @@ class SkillRelUser
$this->acquiredSkillAt = new DateTime();
}
public function setSkill(Skill $skill): self
public function setSkill(?Skill $skill): self
{
$this->skill = $skill;

Loading…
Cancel
Save