symfony-playground/src/DataFixtures/InheritanceFixtures.php

47 lines
1.5 KiB
PHP

<?php
namespace App\DataFixtures;
use App\Entity\Employee1;
use App\Entity\Employee2;
use App\Entity\Employee3;
use App\Entity\Toothbrush1;
use App\Entity\Toothbrush2;
use App\Entity\Toothbrush3;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class InheritanceFixtures //extends Fixture
{
public function load(ObjectManager $manager): void
{
$e1 = new Employee1();
$e1->setJob('peon1')->setName('pepito1')->setAge(20)->setToothbrush((new Toothbrush1())->setBrand('colgate1'));
$manager->persist($e1);
$e1 = new Employee1();
$e1->setJob('jefe1')->setName('benganito1')->setAge(30)->setToothbrush((new Toothbrush1())->setBrand('signal1'));
$manager->persist($e1);
$e2 = new Employee2();
$e2->setJob('peon2')->setName('pepito2')->setAge(20)->setToothbrush((new Toothbrush2())->setBrand('colgate2'));
$manager->persist($e2);
$e2 = new Employee2();
$e2->setJob('jefe2')->setName('benganito2')->setAge(30)->setToothbrush((new Toothbrush2())->setBrand('signal2'));
$manager->persist($e2);
$e3 = new Employee3();
$e3->setJob('peon3')->setName('pepito3')->setAge(20)->setToothbrush((new Toothbrush3())->setBrand('colgate3'));
$manager->persist($e3);
$e3 = new Employee3();
$e3->setJob('jefe3')->setName('benganito3')->setAge(30)->setToothbrush((new Toothbrush3())->setBrand('signal3'));
$manager->persist($e3);
$manager->flush();
}
}
// symfony console doctrine:fixtures:load