Browse Source

OneToMany IndividualData => Territory

master
Charly 3 years ago
parent
commit
4bb272361c
3 changed files with 77 additions and 24 deletions
  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 View File

<?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 View File

private $projectsInspiring; private $projectsInspiring;


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


$this->dreams = new ArrayCollection(); $this->dreams = new ArrayCollection();
$this->projectsBoost = new ArrayCollection(); $this->projectsBoost = new ArrayCollection();
$this->projectsInspiring = new ArrayCollection(); $this->projectsInspiring = new ArrayCollection();
$this->territory = new ArrayCollection();
} }


public function __toString() public function __toString()
return $this; return $this;
} }


/**
* @return Collection|Territory[]
*/
public function getTerritory(): Collection
public function getTerritory(): ?Territory
{ {
return $this->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; return $this;
} }

+ 32
- 1
src/Entity/Territory.php View File

private $name; private $name;


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


public function __construct() public function __construct()
{ {
$this->collectifData = new ArrayCollection(); $this->collectifData = new ArrayCollection();
$this->individualData = new ArrayCollection();
} }


public function __toString() public function __toString()


return $this; 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;
}
} }

Loading…
Cancel
Save