Przeglądaj źródła

OneToMany IndividualData => Territory

master
Charly 3 lat temu
rodzic
commit
4bb272361c
3 zmienionych plików z 77 dodań i 24 usunięć
  1. +41
    -0
      migrations/Version20210609090212.php
  2. +4
    -23
      src/Entity/IndividualData.php
  3. +32
    -1
      src/Entity/Territory.php

+ 41
- 0
migrations/Version20210609090212.php Wyświetl plik

@@ -0,0 +1,41 @@
<?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 Version20210609090212 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 individual_data ADD territory_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE individual_data ADD CONSTRAINT FK_653169D073F74AD4 FOREIGN KEY (territory_id) REFERENCES territory (id)');
$this->addSql('CREATE INDEX IDX_653169D073F74AD4 ON individual_data (territory_id)');
$this->addSql('ALTER TABLE territory DROP FOREIGN KEY FK_E9743966E2920B1');
$this->addSql('DROP INDEX IDX_E9743966E2920B1 ON territory');
$this->addSql('ALTER TABLE territory DROP individual_data_id');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE individual_data DROP FOREIGN KEY FK_653169D073F74AD4');
$this->addSql('DROP INDEX IDX_653169D073F74AD4 ON individual_data');
$this->addSql('ALTER TABLE individual_data DROP territory_id');
$this->addSql('ALTER TABLE territory ADD individual_data_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE territory ADD CONSTRAINT FK_E9743966E2920B1 FOREIGN KEY (individual_data_id) REFERENCES individual_data (id)');
$this->addSql('CREATE INDEX IDX_E9743966E2920B1 ON territory (individual_data_id)');
}
}

+ 4
- 23
src/Entity/IndividualData.php Wyświetl plik

@@ -70,7 +70,7 @@ class IndividualData implements StatusInterface, EntityInterface
private $projectsInspiring;

/**
* @ORM\OneToMany(targetEntity=Territory::class, mappedBy="individualData")
* @ORM\ManyToOne(targetEntity=Territory::class, inversedBy="individualData")
*/
private $territory;

@@ -80,7 +80,6 @@ class IndividualData implements StatusInterface, EntityInterface
$this->dreams = new ArrayCollection();
$this->projectsBoost = new ArrayCollection();
$this->projectsInspiring = new ArrayCollection();
$this->territory = new ArrayCollection();
}

public function __toString()
@@ -273,32 +272,14 @@ class IndividualData implements StatusInterface, EntityInterface
return $this;
}

/**
* @return Collection|Territory[]
*/
public function getTerritory(): Collection
public function getTerritory(): ?Territory
{
return $this->territory;
}

public function addTerritory(Territory $territory): self
public function setTerritory(?Territory $territory): self
{
if (!$this->territory->contains($territory)) {
$this->territory[] = $territory;
$territory->setIndividualData($this);
}

return $this;
}

public function removeTerritory(Territory $territory): self
{
if ($this->territory->removeElement($territory)) {
// set the owning side to null (unless already changed)
if ($territory->getIndividualData() === $this) {
$territory->setIndividualData(null);
}
}
$this->territory = $territory;

return $this;
}

+ 32
- 1
src/Entity/Territory.php Wyświetl plik

@@ -30,7 +30,7 @@ class Territory implements EntityInterface, DevAliasInterface
private $name;

/**
* @ORM\ManyToOne(targetEntity=IndividualData::class, inversedBy="territory")
* @ORM\OneToMany(targetEntity=IndividualData::class, mappedBy="territory")
*/
private $individualData;

@@ -42,6 +42,7 @@ class Territory implements EntityInterface, DevAliasInterface
public function __construct()
{
$this->collectifData = new ArrayCollection();
$this->individualData = new ArrayCollection();
}

public function __toString()
@@ -107,4 +108,34 @@ class Territory implements EntityInterface, DevAliasInterface

return $this;
}

/**
* @return Collection|Territory[]
*/
public function getTerritory(): Collection
{
return $this->territory;
}

public function addTerritory(Territory $territory): self
{
if (!$this->territory->contains($territory)) {
$this->territory[] = $territory;
$territory->setIndividualData($this);
}

return $this;
}

public function removeTerritory(Territory $territory): self
{
if ($this->territory->removeElement($territory)) {
// set the owning side to null (unless already changed)
if ($territory->getIndividualData() === $this) {
$territory->setIndividualData(null);
}
}

return $this;
}
}

Ładowanie…
Anuluj
Zapisz