-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter link #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Chapter link #61
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DoctrineMigrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| /** | ||
| * Auto-generated Migration: Please modify to your needs! | ||
| */ | ||
| final class Version20251016124505 extends AbstractMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return ''; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| // this up() migration is auto-generated, please modify it to your needs | ||
| $this->addSql('ALTER TABLE chapter ADD linked_by_id INT DEFAULT NULL'); | ||
| $this->addSql('ALTER TABLE chapter ADD CONSTRAINT FK_F981B52E1AE3CFF3 FOREIGN KEY (linked_by_id) REFERENCES chapter (id)'); | ||
| $this->addSql('CREATE INDEX IDX_F981B52E1AE3CFF3 ON chapter (linked_by_id)'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| // this down() migration is auto-generated, please modify it to your needs | ||
| $this->addSql('ALTER TABLE chapter DROP FOREIGN KEY FK_F981B52E1AE3CFF3'); | ||
| $this->addSql('DROP INDEX IDX_F981B52E1AE3CFF3 ON chapter'); | ||
| $this->addSql('ALTER TABLE chapter DROP linked_by_id'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| namespace App\Entity; | ||
|
|
||
| use App\Repository\ChapterRepository; | ||
| use Doctrine\Common\Collections\ArrayCollection; | ||
| use Doctrine\Common\Collections\Collection; | ||
| use Doctrine\ORM\Mapping as ORM; | ||
|
|
||
| #[ORM\Entity(repositoryClass: ChapterRepository::class)] | ||
|
|
@@ -21,6 +23,20 @@ class Chapter | |
| #[ORM\JoinColumn(nullable: false)] | ||
| private ?Section $section = null; | ||
|
|
||
| #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'link')] | ||
| private ?self $linkedBy = null; | ||
|
|
||
| /** | ||
| * @var Collection<int, self> | ||
| */ | ||
| #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'chapter')] | ||
| private Collection $link; | ||
|
Comment on lines
+32
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. link est un mot singulier dont la sémantique ne représente pas une collection : le nom de variable en convient pas |
||
|
|
||
| public function __construct() | ||
| { | ||
| $this->link = new ArrayCollection(); | ||
| } | ||
|
|
||
| public function getId(): ?int | ||
| { | ||
| return $this->id; | ||
|
|
@@ -49,4 +65,46 @@ public function setSection(?Section $section): static | |
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function getLinkedBy(): ?self | ||
| { | ||
| return $this->linkedBy; | ||
| } | ||
|
|
||
| public function setLinkedBy(?self $linkedBy): static | ||
| { | ||
| $this->linkedBy = $linkedBy; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @return Collection<int, self> | ||
| */ | ||
| public function getLink(): Collection | ||
| { | ||
| return $this->link; | ||
| } | ||
|
|
||
| public function addLink(self $link): static | ||
| { | ||
| if (!$this->link->contains($link)) { | ||
| $this->link->add($link); | ||
| $link->setLinkedBy($this); | ||
| } | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function removeLink(self $link): static | ||
| { | ||
| if ($this->link->removeElement($link)) { | ||
| // set the owning side to null (unless already changed) | ||
| if ($link->getLinkedBy() === $this) { | ||
| $link->setLinkedBy(null); | ||
| } | ||
| } | ||
|
|
||
| return $this; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu dois faire valider tes noms de champs avant de faire une migration : là tu dois supprimer cette migration vu que le nom du champ ne convient pas