From f6a101d5e789686d1fc8288cb703241e4e124626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Sun, 22 May 2022 18:01:54 +0200 Subject: [PATCH] inheritance --- README.md | 1 + migrations/Version20220522111615.php | 34 ++++++++ migrations/Version20220522115037.php | 48 +++++++++++ migrations/Version20220522153147.php | 64 ++++++++++++++ migrations/Version20220522154942.php | 81 ++++++++++++++++++ src/Controller/IndexController.php | 5 +- src/DataFixtures/InheritanceFixtures.php | 26 ++++++ src/Entity/Employee1.php | 55 ++++++++++++ src/Entity/Employee2.php | 55 ++++++++++++ src/Entity/Employee3.php | 55 ++++++++++++ src/Entity/Person1.php | 75 +++++++++++++++++ src/Entity/Person2.php | 101 +++++++++++++++++++++++ src/Entity/Person3.php | 101 +++++++++++++++++++++++ src/Entity/Toothbrush1.php | 54 ++++++++++++ src/Entity/Toothbrush2.php | 54 ++++++++++++ src/Entity/Toothbrush3.php | 54 ++++++++++++ src/Repository/Entity1Repository.php | 11 +++ templates/index/index.html.twig | 35 +++++++- 18 files changed, 907 insertions(+), 2 deletions(-) create mode 100644 migrations/Version20220522111615.php create mode 100644 migrations/Version20220522115037.php create mode 100644 migrations/Version20220522153147.php create mode 100644 migrations/Version20220522154942.php create mode 100644 src/DataFixtures/InheritanceFixtures.php create mode 100644 src/Entity/Employee1.php create mode 100644 src/Entity/Employee2.php create mode 100644 src/Entity/Employee3.php create mode 100644 src/Entity/Person1.php create mode 100644 src/Entity/Person2.php create mode 100644 src/Entity/Person3.php create mode 100644 src/Entity/Toothbrush1.php create mode 100644 src/Entity/Toothbrush2.php create mode 100644 src/Entity/Toothbrush3.php diff --git a/README.md b/README.md index d3e61c6..ef8b1fe 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ``` symfony server:start +symfony console list make symfony console make:migration symfony console doctrine:migrations:migrate symfony console doctrine:fixtures:load diff --git a/migrations/Version20220522111615.php b/migrations/Version20220522111615.php new file mode 100644 index 0000000..b64fe8c --- /dev/null +++ b/migrations/Version20220522111615.php @@ -0,0 +1,34 @@ +addSql('CREATE TABLE employee1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush1_id INTEGER DEFAULT NULL, job VARCHAR(255) NOT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_2250E3BCA25DC38 ON employee1 (toothbrush1_id)'); + $this->addSql('CREATE TABLE toothbrush1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, brand VARCHAR(255) NOT NULL)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE employee1'); + $this->addSql('DROP TABLE toothbrush1'); + } +} diff --git a/migrations/Version20220522115037.php b/migrations/Version20220522115037.php new file mode 100644 index 0000000..b9080d8 --- /dev/null +++ b/migrations/Version20220522115037.php @@ -0,0 +1,48 @@ +addSql('CREATE TABLE person2 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush2_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, job VARCHAR(255) DEFAULT NULL)'); + $this->addSql('CREATE INDEX IDX_A387B6D5189073D6 ON person2 (toothbrush2_id)'); + $this->addSql('CREATE TABLE toothbrush2 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, brand VARCHAR(255) NOT NULL)'); + $this->addSql('DROP INDEX UNIQ_2250E3BCA25DC38'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee1 AS SELECT id, toothbrush1_id, job, age, name FROM employee1'); + $this->addSql('DROP TABLE employee1'); + $this->addSql('CREATE TABLE employee1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush1_id INTEGER DEFAULT NULL, job VARCHAR(255) NOT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, CONSTRAINT FK_2250E3BCA25DC38 FOREIGN KEY (toothbrush1_id) REFERENCES toothbrush1 (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO employee1 (id, toothbrush1_id, job, age, name) SELECT id, toothbrush1_id, job, age, name FROM __temp__employee1'); + $this->addSql('DROP TABLE __temp__employee1'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_2250E3BCA25DC38 ON employee1 (toothbrush1_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE person2'); + $this->addSql('DROP TABLE toothbrush2'); + $this->addSql('DROP INDEX UNIQ_2250E3BCA25DC38'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee1 AS SELECT id, toothbrush1_id, job, age, name FROM employee1'); + $this->addSql('DROP TABLE employee1'); + $this->addSql('CREATE TABLE employee1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush1_id INTEGER DEFAULT NULL, job VARCHAR(255) NOT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL)'); + $this->addSql('INSERT INTO employee1 (id, toothbrush1_id, job, age, name) SELECT id, toothbrush1_id, job, age, name FROM __temp__employee1'); + $this->addSql('DROP TABLE __temp__employee1'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_2250E3BCA25DC38 ON employee1 (toothbrush1_id)'); + } +} diff --git a/migrations/Version20220522153147.php b/migrations/Version20220522153147.php new file mode 100644 index 0000000..c8a45f6 --- /dev/null +++ b/migrations/Version20220522153147.php @@ -0,0 +1,64 @@ +addSql('CREATE TABLE employee3 (id INTEGER NOT NULL, job VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE person3 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush3_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_D4808643A02C14B3 ON person3 (toothbrush3_id)'); + $this->addSql('CREATE TABLE toothbrush3 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, brand VARCHAR(255) NOT NULL)'); + $this->addSql('DROP INDEX UNIQ_2250E3BCA25DC38'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee1 AS SELECT id, toothbrush1_id, job, age, name FROM employee1'); + $this->addSql('DROP TABLE employee1'); + $this->addSql('CREATE TABLE employee1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush1_id INTEGER DEFAULT NULL, job VARCHAR(255) NOT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, CONSTRAINT FK_2250E3BCA25DC38 FOREIGN KEY (toothbrush1_id) REFERENCES toothbrush1 (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO employee1 (id, toothbrush1_id, job, age, name) SELECT id, toothbrush1_id, job, age, name FROM __temp__employee1'); + $this->addSql('DROP TABLE __temp__employee1'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_2250E3BCA25DC38 ON employee1 (toothbrush1_id)'); + $this->addSql('DROP INDEX IDX_A387B6D5189073D6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__person2 AS SELECT id, toothbrush2_id, age, name, discr, job FROM person2'); + $this->addSql('DROP TABLE person2'); + $this->addSql('CREATE TABLE person2 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush2_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, job VARCHAR(255) DEFAULT NULL, CONSTRAINT FK_A387B6D5189073D6 FOREIGN KEY (toothbrush2_id) REFERENCES toothbrush2 (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO person2 (id, toothbrush2_id, age, name, discr, job) SELECT id, toothbrush2_id, age, name, discr, job FROM __temp__person2'); + $this->addSql('DROP TABLE __temp__person2'); + $this->addSql('CREATE INDEX IDX_A387B6D5189073D6 ON person2 (toothbrush2_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE employee3'); + $this->addSql('DROP TABLE person3'); + $this->addSql('DROP TABLE toothbrush3'); + $this->addSql('DROP INDEX UNIQ_2250E3BCA25DC38'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee1 AS SELECT id, toothbrush1_id, job, age, name FROM employee1'); + $this->addSql('DROP TABLE employee1'); + $this->addSql('CREATE TABLE employee1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush1_id INTEGER DEFAULT NULL, job VARCHAR(255) NOT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL)'); + $this->addSql('INSERT INTO employee1 (id, toothbrush1_id, job, age, name) SELECT id, toothbrush1_id, job, age, name FROM __temp__employee1'); + $this->addSql('DROP TABLE __temp__employee1'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_2250E3BCA25DC38 ON employee1 (toothbrush1_id)'); + $this->addSql('DROP INDEX IDX_A387B6D5189073D6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__person2 AS SELECT id, toothbrush2_id, age, name, discr, job FROM person2'); + $this->addSql('DROP TABLE person2'); + $this->addSql('CREATE TABLE person2 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush2_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, job VARCHAR(255) DEFAULT NULL)'); + $this->addSql('INSERT INTO person2 (id, toothbrush2_id, age, name, discr, job) SELECT id, toothbrush2_id, age, name, discr, job FROM __temp__person2'); + $this->addSql('DROP TABLE __temp__person2'); + $this->addSql('CREATE INDEX IDX_A387B6D5189073D6 ON person2 (toothbrush2_id)'); + } +} diff --git a/migrations/Version20220522154942.php b/migrations/Version20220522154942.php new file mode 100644 index 0000000..eeb8160 --- /dev/null +++ b/migrations/Version20220522154942.php @@ -0,0 +1,81 @@ +addSql('DROP INDEX UNIQ_2250E3BCA25DC38'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee1 AS SELECT id, toothbrush1_id, job, age, name FROM employee1'); + $this->addSql('DROP TABLE employee1'); + $this->addSql('CREATE TABLE employee1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush1_id INTEGER DEFAULT NULL, job VARCHAR(255) NOT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, CONSTRAINT FK_2250E3BCA25DC38 FOREIGN KEY (toothbrush1_id) REFERENCES toothbrush1 (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO employee1 (id, toothbrush1_id, job, age, name) SELECT id, toothbrush1_id, job, age, name FROM __temp__employee1'); + $this->addSql('DROP TABLE __temp__employee1'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_2250E3BCA25DC38 ON employee1 (toothbrush1_id)'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee3 AS SELECT id, job FROM employee3'); + $this->addSql('DROP TABLE employee3'); + $this->addSql('CREATE TABLE employee3 (id INTEGER NOT NULL, job VARCHAR(255) NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_CC5E8290BF396750 FOREIGN KEY (id) REFERENCES person3 (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO employee3 (id, job) SELECT id, job FROM __temp__employee3'); + $this->addSql('DROP TABLE __temp__employee3'); + $this->addSql('DROP INDEX IDX_A387B6D5189073D6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__person2 AS SELECT id, toothbrush2_id, age, name, discr, job FROM person2'); + $this->addSql('DROP TABLE person2'); + $this->addSql('CREATE TABLE person2 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush2_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, job VARCHAR(255) DEFAULT NULL, CONSTRAINT FK_A387B6D5189073D6 FOREIGN KEY (toothbrush2_id) REFERENCES toothbrush2 (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO person2 (id, toothbrush2_id, age, name, discr, job) SELECT id, toothbrush2_id, age, name, discr, job FROM __temp__person2'); + $this->addSql('DROP TABLE __temp__person2'); + $this->addSql('CREATE INDEX IDX_A387B6D5189073D6 ON person2 (toothbrush2_id)'); + $this->addSql('DROP INDEX UNIQ_D4808643A02C14B3'); + $this->addSql('CREATE TEMPORARY TABLE __temp__person3 AS SELECT id, toothbrush3_id, age, name, discr FROM person3'); + $this->addSql('DROP TABLE person3'); + $this->addSql('CREATE TABLE person3 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush3_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, CONSTRAINT FK_D4808643A02C14B3 FOREIGN KEY (toothbrush3_id) REFERENCES toothbrush3 (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO person3 (id, toothbrush3_id, age, name, discr) SELECT id, toothbrush3_id, age, name, discr FROM __temp__person3'); + $this->addSql('DROP TABLE __temp__person3'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_D4808643A02C14B3 ON person3 (toothbrush3_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP INDEX UNIQ_2250E3BCA25DC38'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee1 AS SELECT id, toothbrush1_id, job, age, name FROM employee1'); + $this->addSql('DROP TABLE employee1'); + $this->addSql('CREATE TABLE employee1 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush1_id INTEGER DEFAULT NULL, job VARCHAR(255) NOT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL)'); + $this->addSql('INSERT INTO employee1 (id, toothbrush1_id, job, age, name) SELECT id, toothbrush1_id, job, age, name FROM __temp__employee1'); + $this->addSql('DROP TABLE __temp__employee1'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_2250E3BCA25DC38 ON employee1 (toothbrush1_id)'); + $this->addSql('CREATE TEMPORARY TABLE __temp__employee3 AS SELECT id, job FROM employee3'); + $this->addSql('DROP TABLE employee3'); + $this->addSql('CREATE TABLE employee3 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, job VARCHAR(255) NOT NULL)'); + $this->addSql('INSERT INTO employee3 (id, job) SELECT id, job FROM __temp__employee3'); + $this->addSql('DROP TABLE __temp__employee3'); + $this->addSql('DROP INDEX IDX_A387B6D5189073D6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__person2 AS SELECT id, toothbrush2_id, age, name, discr, job FROM person2'); + $this->addSql('DROP TABLE person2'); + $this->addSql('CREATE TABLE person2 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush2_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL, job VARCHAR(255) DEFAULT NULL)'); + $this->addSql('INSERT INTO person2 (id, toothbrush2_id, age, name, discr, job) SELECT id, toothbrush2_id, age, name, discr, job FROM __temp__person2'); + $this->addSql('DROP TABLE __temp__person2'); + $this->addSql('CREATE INDEX IDX_A387B6D5189073D6 ON person2 (toothbrush2_id)'); + $this->addSql('DROP INDEX UNIQ_D4808643A02C14B3'); + $this->addSql('CREATE TEMPORARY TABLE __temp__person3 AS SELECT id, toothbrush3_id, age, name, discr FROM person3'); + $this->addSql('DROP TABLE person3'); + $this->addSql('CREATE TABLE person3 (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, toothbrush3_id INTEGER DEFAULT NULL, age INTEGER NOT NULL, name VARCHAR(255) NOT NULL, discr VARCHAR(255) NOT NULL)'); + $this->addSql('INSERT INTO person3 (id, toothbrush3_id, age, name, discr) SELECT id, toothbrush3_id, age, name, discr FROM __temp__person3'); + $this->addSql('DROP TABLE __temp__person3'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_D4808643A02C14B3 ON person3 (toothbrush3_id)'); + } +} diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index 8498bfc..cf901e0 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use Doctrine\ORM\EntityManager; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -12,11 +13,13 @@ class IndexController extends AbstractController #[Route('/', name: 'app_index')] public function index(Entity1Repository $repo): Response { + $sm = $repo->getSchemaManager(); $entity8 = $repo->findOneByName('entity 8'); return $this->render('index/index.html.twig', [ 'controller_name' => 'IndexController', - 'entity8' => $entity8 + 'entity8' => $entity8, + 'schemaManager' => $sm ]); } } diff --git a/src/DataFixtures/InheritanceFixtures.php b/src/DataFixtures/InheritanceFixtures.php new file mode 100644 index 0000000..c85b10f --- /dev/null +++ b/src/DataFixtures/InheritanceFixtures.php @@ -0,0 +1,26 @@ +setJob('peon')->setName('pepito')->setAge(20)->setToothbrush((new Toothbrush1())->setBrand('colgate')); + $manager->persist($e1); + + $e1 = new Employee1(); + $e1->setJob('jefe')->setName('benganito')->setAge(30)->setToothbrush((new Toothbrush1())->setBrand('signal')); + $manager->persist($e1); + + $manager->flush(); + } +} + +// symfony console doctrine:fixtures:load diff --git a/src/Entity/Employee1.php b/src/Entity/Employee1.php new file mode 100644 index 0000000..dbfd745 --- /dev/null +++ b/src/Entity/Employee1.php @@ -0,0 +1,55 @@ +id; + } + + /** + * @param int $id + * @return Employee1 + */ + public function setId(int $id): Employee1 + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getJob(): string + { + return $this->job; + } + + /** + * @param string $job + * @return Employee1 + */ + public function setJob(string $job): Employee1 + { + $this->job = $job; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Entity/Employee2.php b/src/Entity/Employee2.php new file mode 100644 index 0000000..5a22219 --- /dev/null +++ b/src/Entity/Employee2.php @@ -0,0 +1,55 @@ +id; + } + + /** + * @param int $id + * @return Employee2 + */ + public function setId(int $id): Employee2 + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getJob(): string + { + return $this->job; + } + + /** + * @param string $job + * @return Employee2 + */ + public function setJob(string $job): Employee2 + { + $this->job = $job; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Entity/Employee3.php b/src/Entity/Employee3.php new file mode 100644 index 0000000..e5dff6e --- /dev/null +++ b/src/Entity/Employee3.php @@ -0,0 +1,55 @@ +id; + } + + /** + * @param int $id + * @return Employee3 + */ + public function setId(int $id): Employee3 + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getJob(): string + { + return $this->job; + } + + /** + * @param string $job + * @return Employee3 + */ + public function setJob(string $job): Employee3 + { + $this->job = $job; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Entity/Person1.php b/src/Entity/Person1.php new file mode 100644 index 0000000..bc5fdc2 --- /dev/null +++ b/src/Entity/Person1.php @@ -0,0 +1,75 @@ +age; + } + + /** + * @param int $age + * @return Person1 + */ + public function setAge(int $age): Person1 + { + $this->age = $age; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + * @return Person1 + */ + public function setName(string $name): Person1 + { + $this->name = $name; + return $this; + } + + /** + * @return Toothbrush1 + */ + public function getToothbrush(): Toothbrush1 + { + return $this->toothbrush; + } + + /** + * @param Toothbrush1 $toothbrush + * @return Person1 + */ + public function setToothbrush(Toothbrush1 $toothbrush): Person1 + { + $this->toothbrush = $toothbrush; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Entity/Person2.php b/src/Entity/Person2.php new file mode 100644 index 0000000..83b5fa6 --- /dev/null +++ b/src/Entity/Person2.php @@ -0,0 +1,101 @@ + 'Person2', 'employee2' => 'Employee2'])] +class Person2 +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] + private int $id; + + #[ORM\Column(type: 'integer')] + protected int $age; + + #[ORM\Column(type: 'string')] + protected string $name; + + #[ORM\OneToOne(targetEntity: 'Toothbrush2', cascade: ['persist'])] + #[ORM\JoinColumn(name: 'toothbrush2_id', referencedColumnName: 'id')] + protected Toothbrush2 $toothbrush; + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $id + * @return Person2 + */ + public function setId(int $id): Person2 + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getAge(): int + { + return $this->age; + } + + /** + * @param int $age + * @return Person2 + */ + public function setAge(int $age): Person2 + { + $this->age = $age; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + * @return Person2 + */ + public function setName(string $name): Person2 + { + $this->name = $name; + return $this; + } + + /** + * @return Toothbrush2 + */ + public function getToothbrush(): Toothbrush2 + { + return $this->toothbrush; + } + + /** + * @param Toothbrush2 $toothbrush + * @return Person2 + */ + public function setToothbrush(Toothbrush2 $toothbrush): Person2 + { + $this->toothbrush = $toothbrush; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Entity/Person3.php b/src/Entity/Person3.php new file mode 100644 index 0000000..314ab0a --- /dev/null +++ b/src/Entity/Person3.php @@ -0,0 +1,101 @@ + 'Person3', 'employee3' => 'Employee3'])] +class Person3 +{ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] + private int $id; + + #[ORM\Column(type: 'integer')] + protected int $age; + + #[ORM\Column(type: 'string')] + protected string $name; + + #[ORM\OneToOne(targetEntity: 'Toothbrush3', cascade: ['persist'])] + #[ORM\JoinColumn(name: 'toothbrush3_id', referencedColumnName: 'id')] + protected Toothbrush3 $toothbrush; + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $id + * @return Person3 + */ + public function setId(int $id): Person3 + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getAge(): int + { + return $this->age; + } + + /** + * @param int $age + * @return Person3 + */ + public function setAge(int $age): Person3 + { + $this->age = $age; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + * @return Person3 + */ + public function setName(string $name): Person3 + { + $this->name = $name; + return $this; + } + + /** + * @return Toothbrush3 + */ + public function getToothbrush(): Toothbrush3 + { + return $this->toothbrush; + } + + /** + * @param Toothbrush3 $toothbrush + * @return Person3 + */ + public function setToothbrush(Toothbrush3 $toothbrush): Person3 + { + $this->toothbrush = $toothbrush; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Entity/Toothbrush1.php b/src/Entity/Toothbrush1.php new file mode 100644 index 0000000..bcf4488 --- /dev/null +++ b/src/Entity/Toothbrush1.php @@ -0,0 +1,54 @@ +id; + } + + /** + * @param int $id + * @return Toothbrush1 + */ + public function setId(int $id): Toothbrush1 + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getBrand(): string + { + return $this->brand; + } + + /** + * @param string $brand + * @return Toothbrush1 + */ + public function setBrand(string $brand): Toothbrush1 + { + $this->brand = $brand; + return $this; + } + +} \ No newline at end of file diff --git a/src/Entity/Toothbrush2.php b/src/Entity/Toothbrush2.php new file mode 100644 index 0000000..33b8ef6 --- /dev/null +++ b/src/Entity/Toothbrush2.php @@ -0,0 +1,54 @@ +id; + } + + /** + * @param int $id + * @return Toothbrush2 + */ + public function setId(int $id): Toothbrush2 + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getBrand(): string + { + return $this->brand; + } + + /** + * @param string $brand + * @return Toothbrush2 + */ + public function setBrand(string $brand): Toothbrush2 + { + $this->brand = $brand; + return $this; + } + +} \ No newline at end of file diff --git a/src/Entity/Toothbrush3.php b/src/Entity/Toothbrush3.php new file mode 100644 index 0000000..348e14b --- /dev/null +++ b/src/Entity/Toothbrush3.php @@ -0,0 +1,54 @@ +id; + } + + /** + * @param int $id + * @return Toothbrush3 + */ + public function setId(int $id): Toothbrush3 + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getBrand(): string + { + return $this->brand; + } + + /** + * @param string $brand + * @return Toothbrush3 + */ + public function setBrand(string $brand): Toothbrush3 + { + $this->brand = $brand; + return $this; + } + +} \ No newline at end of file diff --git a/src/Repository/Entity1Repository.php b/src/Repository/Entity1Repository.php index f180663..b3edccb 100644 --- a/src/Repository/Entity1Repository.php +++ b/src/Repository/Entity1Repository.php @@ -63,4 +63,15 @@ class Entity1Repository extends ServiceEntityRepository ->getOneOrNullResult() ; } + + /** + * https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html + * + * @return \Doctrine\DBAL\Schema\AbstractSchemaManager|null + * @throws \Doctrine\DBAL\Exception + */ + public function getSchemaManager() + { + return $this->getEntityManager()->getConnection()->getSchemaManager(); + } } diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index 03030a5..5161250 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -4,6 +4,11 @@ {% block body %} @@ -18,5 +23,33 @@ -

entity8: {{ entity8.id }}

+ {% endblock %}