Jump to content

NotionCommotion

Members
  • Content Count

    1,767
  • Joined

  • Last visited

  • Days Won

    8

NotionCommotion last won the day on January 3

NotionCommotion had the most liked content!

Community Reputation

28 Good

About NotionCommotion

  • Rank
    Prolific Member

Contact Methods

  • Website URL
    http://

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. NotionCommotion

    Doctrine, Composer, and namespace

    Immediate issue solved. It appears that all extended classes (and not just intermediate extended classes) need to included in the grandparent's explicit distriminatorMap. Also, at least one of the intermediate extended classes needs to have an explicit distriminatorMap. Also, the distriminatorColumn needs to be defined in any extended classes (i.e. AirVehicles and GroundVehicles) which also extend other classes, and needs to use the same name as the grandparent's distriminatorColumn. I didn't come across any documentation to this effect, but it seems to work as desired. #MyNamespace.MyApp.Vehicle.Vehicle.dcm.yml MyNamespace\MyApp\Vehicle\Vehicle: type: entity table: vehicle_table inheritanceType: JOINED discriminatorColumn: name: discriminator_column type: string discriminatorMap: vehicle: Vehicle airvehicle: MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle car: MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car train: MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train groundvehicle: MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle airplane: MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane rocket: MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket repositoryClass: VehicleRepository id: id: type: integer generator: strategy: AUTO fields: grandParentItem1: type: string grandParentItem2: type: string #MyNamespace.MyApp.Vehicle.AirVehicle.AirVehicle.dcm.yml MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle: type: entity table: air_vehicle extends: MyNamespace\MyApp\Vehicle\Vehicle inheritanceType: JOINED discriminatorColumn: name: discriminator_column type: string discriminatorMap: airVehicle: AirVehicle airplane: MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane rocket: MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket repositoryClass: AirVehicleRepository id: id: associationKey: true fields: parentItem1: type: string parentItem2: type: string <?php //use MyNamespace\MyApp; error_reporting(E_ALL); ini_set("log_errors", '1'); ini_set('display_startup_errors', '1'); ini_set('display_errors', '1'); require_once "../bootstrap.php"; function createObj($em, $class) { $cn=explode('\\', $class); $cn=$cn[count($cn)-1]; $entity = new $class(); $entity->setChildItem1("$cn c1"); $entity->setChildItem2("$cn c2"); $entity->setParentItem1("$cn p1"); $entity->setParentItem2("$cn p2"); $entity->setGrandParentItem1("$cn g1"); $entity->setGrandParentItem2("$cn g2"); try{ $em->persist($entity); $em->flush(); echo "Created $class with ID " . $entity->getId() . "\n\n"; } catch(\Exception $e) { echo($class.' - '.$e->getMessage()."\n\n"); } } function displayMember($em, $class, $id) { echo("Display Member $id for $class\n\n"); try{ $member=$em->find($class, $id); print_r($member); } catch(\Exception $e) { echo($class.' - '.$e->getMessage()."\n\n"); } } function displayAllMembers($em, $class) { echo("Diaplay All Members for $class\n\n"); $repository = $em->getRepository($class); try{ $members=$repository->findAll(); print_r($members); } catch(\Exception $e) { echo($class.' - '.$e->getMessage()."\n\n"); } } $entities=[ 'Vehicle'=>['class'=>'\MyNamespace\MyApp\Vehicle\Vehicle','children'=>[ 'AirVehicle'=>['class'=>'\MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle','children'=>[ 'Rocket'=>'\MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket', 'Airplane'=>'\MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane' ]], 'GroundVehicle'=>['class'=>'\MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle','children'=>[ 'Train'=>'\MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train', 'Car'=>'\MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car' ]], ] ], ]; //Creating works correctly foreach($entities as $grandparentName=>$grandparent) { //createObj($em, $grandparent['class']); //Abstract foreach($grandparent['children'] as $parentName=>$parent) { //createObj($em, $parent['class']); //Abstract foreach($parent['children'] as $childName=>$class) { createObj($em, $class); } } } displayMember($em, '\MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket', 1); displayMember($em, '\MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle', 1); displayMember($em, '\MyNamespace\MyApp\Vehicle\Vehicle', 1); foreach($entities as $grandparentName=>$grandparent) { displayAllMembers($em, $grandparent['class']); foreach($grandparent['children'] as $parentName=>$parent) { displayAllMembers($em, $parent['class']); foreach($parent['children'] as $class) { displayAllMembers($em, $class); } } } Created \MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket with ID 5 Created \MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane with ID 6 Created \MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train with ID 7 Created \MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car with ID 8 Display Member 1 for \MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 1 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) Display Member 1 for \MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 1 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) Display Member 1 for \MyNamespace\MyApp\Vehicle\Vehicle MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 1 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) Diaplay All Members for \MyNamespace\MyApp\Vehicle\Vehicle Array ( [0] => MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 1 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) [1] => MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 2 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g2 ) [2] => MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 3 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g2 ) [3] => MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 4 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g2 ) [4] => MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 5 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) [5] => MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 6 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g2 ) [6] => MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 7 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g2 ) [7] => MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 8 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g2 ) ) Diaplay All Members for \MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle Array ( [0] => MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 3 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g2 ) [1] => MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 4 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g2 ) [2] => MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 7 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g2 ) [3] => MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 8 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g2 ) ) Diaplay All Members for \MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Array ( [0] => MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 1 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) [1] => MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 5 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) ) Diaplay All Members for \MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane Array ( [0] => MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 2 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g2 ) [1] => MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 6 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g2 ) ) Diaplay All Members for \MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle Array ( [0] => MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 1 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) [1] => MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 2 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g2 ) [2] => MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket:private] => Rocket c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Rocket p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 5 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Rocket g2 ) [3] => MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane Object ( [childItem1:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c1 [childItem2:MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane:private] => Airplane c2 [parentItem1:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p1 [parentItem2:MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle:private] => Airplane p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 6 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Airplane g2 ) ) Diaplay All Members for \MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train Array ( [0] => MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 3 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g2 ) [1] => MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train:private] => Train c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Train p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 7 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Train g2 ) ) Diaplay All Members for \MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car Array ( [0] => MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 4 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g2 ) [1] => MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car Object ( [childItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c1 [childItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car:private] => Car c2 [parentItem1:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p1 [parentItem2:MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle:private] => Car p2 [id:MyNamespace\MyApp\Vehicle\Vehicle:private] => 8 [grandParentItem1:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g1 [grandParentItem2:MyNamespace\MyApp\Vehicle\Vehicle:private] => Car g2 ) )
  2. NotionCommotion

    Doctrine, Composer, and namespace

    @benanamen, I am building a web interface to manage various industrial integration gateways. Some act as servers and others act as clients. Some utilize ethernet and others utilize rs-485 serial communication. Typical protocols include modbus, devicenet, bacnet, lonworks, profibus, etc. To implement this, I am creating an object (with injected other objects) for each which fulfills the required functionality. There are some portions where inheritance is well fit and I wish to extend classes. Current implementation uses a mapper class to pull the various properties from the db which are injected into an entity object. Everything is vanilla PHP without some 3rd party framework and it works as desired, but is becoming more and more difficult to manage, and I feel that maybe I should be using some dedicated orm. Maybe I shouldn't be using an orm (and if so, whether it should be doctrine), but the only way I know how to confirm this is to personally try it out and create new entities, retrieve one by its ID, retrieve a set of them, modify them, etc. And while I can do this initially for the entire application, it is much simpler to do so for a mock application of vehicles, rockets, etc. So... assuming this is just an academic exercise to create a Rocket that is inherited from a Vehicle, does my entity meta data look reasonable? Do you know why I am unable to retrieve an entity by ID or retrieve a group of entities? Thanks
  3. NotionCommotion

    Doctrine, Composer, and namespace

    I appreciate your passion to abolishing all xy problems, however, I am not asking for you to build something for me but for you to teach me something. Specifically, how to implement Class Table Inheritance using Doctrine.
  4. NotionCommotion

    Doctrine, Composer, and namespace

    Below is some sample data. SELECT *, 'airplane' FROM vehicle_table vt INNER JOIN air_vehicle av ON av.id=vt.id INNER JOIN airplane_table ap ON ap.id=av.id WHERE vt.id>=32 AND vt.id<=42 UNION SELECT *, 'rocket' FROM vehicle_table vt INNER JOIN air_vehicle av ON av.id=vt.id INNER JOIN rocket_table rt ON rt.id=av.id WHERE vt.id>=32 AND vt.id<=42 UNION SELECT *, 'car' FROM vehicle_table vt INNER JOIN ground_vehicle gv ON gv.id=vt.id INNER JOIN car_table ct ON ct.id=gv.id WHERE vt.id>=32 AND vt.id<=42 UNION SELECT *, 'train' FROM vehicle_table vt INNER JOIN ground_vehicle gv ON gv.id=vt.id INNER JOIN train_table tt ON tt.id=gv.id WHERE vt.id>=32 AND vt.id<=42; id grandParentItem1 grandParentItem2 discriminator_column id parentItem1 parentItem2 id childItem1 childItem2 type 32 Airplane g1 Airplane g2 airplane 32 Airplane p1 Airplane p2 32 Airplane c1 Airplane c2 airplane 36 Airplane g1 Airplane g2 airplane 36 Airplane p1 Airplane p2 36 Airplane c1 Airplane c2 airplane 40 Airplane g1 Airplane g2 airplane 40 Airplane p1 Airplane p2 40 Airplane c1 Airplane c2 airplane 35 Rocket g1 Rocket g2 rocket 35 Rocket p1 Rocket p2 35 Rocket c1 Rocket c2 rocket 39 Rocket g1 Rocket g2 rocket 39 Rocket p1 Rocket p2 39 Rocket c1 Rocket c2 rocket 34 Car g1 Car g2 car 34 Car p1 Car p2 34 Car c1 Car c2 car 38 Car g1 Car g2 car 38 Car p1 Car p2 38 Car c1 Car c2 car 42 Car g1 Car g2 car 42 Car p1 Car p2 42 Car c1 Car c2 car 33 Train g1 Train g2 train 33 Train p1 Train p2 33 Train c1 Train c2 train 37 Train g1 Train g2 train 37 Train p1 Train p2 37 Train c1 Train c2 train 41 Train g1 Train g2 train 41 Train p1 Train p2 41 Train c1 Train c2 train
  5. NotionCommotion

    Doctrine, Composer, and namespace

    Hello benanamen, I've never used a 3rd party ORM before and have previously used homespun scripts of my own. Have you ever used one, and specifically have you ever used Doctrine? The reason I put my Vehicle/AirVehicle/Rocket example together was primarily so I can get a small simple implementation working before deploying it to a more complicated application. I can successfully create new entities and store them in the database as shown by my previous post, but have not been successful retrieving all entities of a given type nor retrieving a given entity by ID. Do you know what I am doing wrong? Thanks
  6. NotionCommotion

    Doctrine, Composer, and namespace

    Looks like something is not right. Any ideas? <?php //use MyNamespace\MyApp; error_reporting(E_ALL); ini_set("log_errors", '1'); ini_set('display_startup_errors', '1'); ini_set('display_errors', '1'); require_once "../bootstrap.php"; function createObj($em, $class) { $cn=explode('\\', $class); $cn=$cn[count($cn)-1]; $entity = new $class(); $entity->setChildItem1("$cn c1"); $entity->setChildItem2("$cn c2"); $entity->setParentItem1("$cn p1"); $entity->setParentItem2("$cn p2"); $entity->setGrandParentItem1("$cn g1"); $entity->setGrandParentItem2("$cn g2"); try{ $em->persist($entity); $em->flush(); echo "Created $class with ID " . $entity->getId() . "\n\n"; } catch(\Exception $e) { echo($class.' - '.$e->getMessage()."\n\n"); } } function displayMember($em, $class, $id) { try{ $member=$em->find($class, $id); echo("Member $id for $class\n\n"); print_r($member); } catch(\Exception $e) { echo($class.' - '.$e->getMessage()."\n\n"); } } function displayAllMembers($em, $class) { $repository = $em->getRepository($class); try{ $members=$repository->findAll(); echo("Members for $class\n\n"); print_r($members); } catch(\Exception $e) { echo($class.' - '.$e->getMessage()."\n\n"); } } $entities=[ 'Vehicle'=>['class'=>'\MyNamespace\MyApp\Vehicle\Vehicle','children'=>[ 'AirVehicle'=>['class'=>'\MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle','children'=>[ 'Train'=>'\MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train', 'Car'=>'\MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car' ]], 'GroundVehicle'=>['class'=>'\MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle','children'=>[ 'Rocket'=>'\MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket', 'Airplane'=>'\MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane' ]] ] ], ]; //Creating works correctly foreach($entities as $grandparentName=>$grandparent) { //createObj($em, $grandparent['class']); //Abstract foreach($grandparent['children'] as $parentName=>$parent) { //createObj($em, $parent['class']); //Abstract foreach($parent['children'] as $childName=>$class) { createObj($em, $class); } } } displayMember($em, '\MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train', 37); displayMember($em, '\MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle', 37); displayMember($em, '\MyNamespace\MyApp\Vehicle\Vehicle', 37); foreach($entities as $grandparentName=>$grandparent) { displayAllMembers($em, $grandparent['class']); foreach($grandparent['children'] as $parentName=>$parent) { displayAllMembers($em, $parent['class']); foreach($parent['children'] as $class) { displayAllMembers($em, $class); } } } Created \MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train with ID 53 Created \MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car with ID 54 Created \MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket with ID 55 Created \MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane with ID 56 \MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train - An exception occurred while executing 'SELECT t2.id AS id_3, t2.grandParentItem1 AS grandParentItem1_4, t2.grandParentItem2 AS grandParentItem2_5, t1.parentItem1 AS parentItem1_6, t1.parentItem2 AS parentItem2_7, t0.childItem1 AS childItem1_8, t0.childItem2 AS childItem2_9, t2.dtype FROM train_table t0 INNER JOIN ground_vehicle t1 ON t0.id = t1.id INNER JOIN vehicle_table t2 ON t0.id = t2.id WHERE t2.id = ?' with params [37]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2.dtype' in 'field list' \MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle - An exception occurred while executing 'SELECT t1.id AS id_4, t1.grandParentItem1 AS grandParentItem1_5, t1.grandParentItem2 AS grandParentItem2_6, t0.parentItem1 AS parentItem1_7, t0.parentItem2 AS parentItem2_8, t1.dtype, t2.childItem1 AS childItem1_9, t2.childItem2 AS childItem2_10, t3.childItem1 AS childItem1_11, t3.childItem2 AS childItem2_12 FROM ground_vehicle t0 INNER JOIN vehicle_table t1 ON t0.id = t1.id LEFT JOIN train_table t2 ON t0.id = t2.id LEFT JOIN car_table t3 ON t0.id = t3.id WHERE t1.id = ?' with params [37]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't1.dtype' in 'field list' \MyNamespace\MyApp\Vehicle\Vehicle - The discriminator value "train" is invalid. It must be one of "vehicle", "groundVehicle", "airVehicle". \MyNamespace\MyApp\Vehicle\Vehicle - The discriminator value "airplane" is invalid. It must be one of "vehicle", "groundVehicle", "airVehicle". \MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle - An exception occurred while executing 'SELECT t1.id AS id_4, t1.grandParentItem1 AS grandParentItem1_5, t1.grandParentItem2 AS grandParentItem2_6, t0.parentItem1 AS parentItem1_7, t0.parentItem2 AS parentItem2_8, t1.dtype, t2.childItem1 AS childItem1_9, t2.childItem2 AS childItem2_10, t3.childItem1 AS childItem1_11, t3.childItem2 AS childItem2_12 FROM ground_vehicle t0 INNER JOIN vehicle_table t1 ON t0.id = t1.id LEFT JOIN train_table t2 ON t0.id = t2.id LEFT JOIN car_table t3 ON t0.id = t3.id': SQLSTATE[42S22]: Column not found: 1054 Unknown column 't1.dtype' in 'field list' \MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train - An exception occurred while executing 'SELECT t2.id AS id_3, t2.grandParentItem1 AS grandParentItem1_4, t2.grandParentItem2 AS grandParentItem2_5, t1.parentItem1 AS parentItem1_6, t1.parentItem2 AS parentItem2_7, t0.childItem1 AS childItem1_8, t0.childItem2 AS childItem2_9, t2.dtype FROM train_table t0 INNER JOIN ground_vehicle t1 ON t0.id = t1.id INNER JOIN vehicle_table t2 ON t0.id = t2.id': SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2.dtype' in 'field list' \MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car - An exception occurred while executing 'SELECT t2.id AS id_3, t2.grandParentItem1 AS grandParentItem1_4, t2.grandParentItem2 AS grandParentItem2_5, t1.parentItem1 AS parentItem1_6, t1.parentItem2 AS parentItem2_7, t0.childItem1 AS childItem1_8, t0.childItem2 AS childItem2_9, t2.dtype FROM car_table t0 INNER JOIN ground_vehicle t1 ON t0.id = t1.id INNER JOIN vehicle_table t2 ON t0.id = t2.id': SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2.dtype' in 'field list' \MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle - An exception occurred while executing 'SELECT t1.id AS id_4, t1.grandParentItem1 AS grandParentItem1_5, t1.grandParentItem2 AS grandParentItem2_6, t0.parentItem1 AS parentItem1_7, t0.parentItem2 AS parentItem2_8, t1.dtype, t2.childItem1 AS childItem1_9, t2.childItem2 AS childItem2_10, t3.childItem1 AS childItem1_11, t3.childItem2 AS childItem2_12 FROM air_vehicle t0 INNER JOIN vehicle_table t1 ON t0.id = t1.id LEFT JOIN airplane_table t2 ON t0.id = t2.id LEFT JOIN rocket_table t3 ON t0.id = t3.id': SQLSTATE[42S22]: Column not found: 1054 Unknown column 't1.dtype' in 'field list' \MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket - An exception occurred while executing 'SELECT t2.id AS id_3, t2.grandParentItem1 AS grandParentItem1_4, t2.grandParentItem2 AS grandParentItem2_5, t1.parentItem1 AS parentItem1_6, t1.parentItem2 AS parentItem2_7, t0.childItem1 AS childItem1_8, t0.childItem2 AS childItem2_9, t2.dtype FROM rocket_table t0 INNER JOIN air_vehicle t1 ON t0.id = t1.id INNER JOIN vehicle_table t2 ON t0.id = t2.id': SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2.dtype' in 'field list' \MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane - An exception occurred while executing 'SELECT t2.id AS id_3, t2.grandParentItem1 AS grandParentItem1_4, t2.grandParentItem2 AS grandParentItem2_5, t1.parentItem1 AS parentItem1_6, t1.parentItem2 AS parentItem2_7, t0.childItem1 AS childItem1_8, t0.childItem2 AS childItem2_9, t2.dtype FROM airplane_table t0 INNER JOIN air_vehicle t1 ON t0.id = t1.id INNER JOIN vehicle_table t2 ON t0.id = t2.id': SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2.dtype' in 'field list'
  7. NotionCommotion

    Doctrine, Composer, and namespace

    I think I am close, but not sure if I am quite there. Am I doing this correctly? I have several entity classes which will use class type inheritance: MyNamespace\MyApp\Vehicle\Vehicle MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle MyNamespace\MyApp\Vehicle\GroundVehicle\Car\Car MyNamespace\MyApp\Vehicle\GroundVehicle\Train\Train The entity meta data is as follows: #MyNamespace.MyApp.Vehicle.Vehicle.dcm.yml MyNamespace\MyApp\Vehicle\Vehicle: type: entity table: vehicle_table inheritanceType: JOINED discriminatorColumn: name: discriminator_column type: string discriminatorMap: vehicle: Vehicle groundVehicle: MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle airVehicle: MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle repositoryClass: Vehicle id: id: type: integer generator: strategy: AUTO fields: grandParentItem1: type: string grandParentItem2: type: string #MyNamespace.MyApp.Vehicle.AirVehicle.AirVehicle.dcm.yml MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle: type: entity table: air_vehicle extends: MyNamespace\MyApp\Vehicle\Vehicle inheritanceType: JOINED discriminatorMap: airVehicle: AirVehicle airplane: MyNamespace\MyApp\Vehicle\AirVehicle\Airplane\Airplane rocket: MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket repositoryClass: AirVehicle id: id: associationKey: true fields: parentItem1: type: string parentItem2: type: string #MyNamespace.MyApp.Vehicle.AirVehicle.Rocket.Rocket.dcm.yml MyNamespace\MyApp\Vehicle\AirVehicle\Rocket\Rocket: extends: MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle type: entity table: rocket_table id: id: associationKey: true repositoryClass: Rocket fields: childItem1: type: string childItem2: type: string I haven't shown GroundVehicle or Train, Car, and Airplane, but they are almost identical to AirVehicle and Rocket, respectively. I've discovered that the barebone entities need to be manually created prior to using orm:generate-entities else I get class not found errors, and have created them as shown below. inheritance_src/MyNamespace/MyApp/Vehicle/Vehicle.php inheritance_src/MyNamespace/MyApp/Vehicle/AirVehicle/AirVehicle.php inheritance_src/MyNamespace/MyApp/Vehicle/AirVehicle/Airplane/Airplane.php inheritance_src/MyNamespace/MyApp/Vehicle/AirVehicle/Rocket/Rocket.php inheritance_src/MyNamespace/MyApp/Vehicle/GroundVehicle/GroundVehicle.php inheritance_src/MyNamespace/MyApp/Vehicle/GroundVehicle/Car/Car.php inheritance_src/MyNamespace/MyApp/Vehicle/GroundVehicle/Train/Train.php [michael@devserver doctrine]$ find inheritance_src -name "*.php" -exec cat {} \; <?php namespace MyNamespace\MyApp\Vehicle\AirVehicle\Airplane; class Airplane extends \MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle{} <?php namespace MyNamespace\MyApp\Vehicle\AirVehicle\Rocket; class Rocket extends \MyNamespace\MyApp\Vehicle\AirVehicle\AirVehicle{} <?php namespace MyNamespace\MyApp\Vehicle\AirVehicle; abstract class AirVehicle extends \MyNamespace\MyApp\Vehicle\Vehicle{} <?php namespace MyNamespace\MyApp\Vehicle\GroundVehicle\Car; class Car extends \MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle{} <?php namespace MyNamespace\MyApp\Vehicle\GroundVehicle\Train; class Train extends \MyNamespace\MyApp\Vehicle\GroundVehicle\GroundVehicle{} <?php namespace MyNamespace\MyApp\Vehicle\GroundVehicle; abstract class GroundVehicle extends \MyNamespace\MyApp\Vehicle\Vehicle{} <?php namespace MyNamespace\MyApp\Vehicle; abstract class Vehicle{} I then am able to successfully create the entities using orm:generate-entities, schema using orm:schema-tool:create, and repositories using orm:generate-repositories. Does everything seem correct? A couple of issues which I have my doubts: Locating the classes in inheritance_src/MyNamespace/MyApp instead of inheritance_src/MyApp. I tried to do the later and modify my psr-4 autoloader to use "MyNamespace\\": "inheritance_src/", but could not get it working without first creating the entities, editing them to add the "abstract" and "extend" portions, and then moving them to one directory lower. Needing to manually create the barebone classes in the first place. My meta-data definitions includes "extends: MyNamespace\MyApp\Vehicle\Vehicle", so I would thought it would not be necessary. Locate both the entities and repositories in the same folder. For that matter, I will probably be locating my service in the same folder as well. It seems that most frameworks will locate all the entities in one folder (with of course subdirectories), repositories in another, services in another, etc. The way I am doing seems to be organized domain modules as described by https://mnapoli.fr/organizing-code-into-domain-modules/. Any compelling reasons to do it one way or the other? Thank you
  8. NotionCommotion

    Doctrine class table inheritance help

    Ah, it just stores the name of the final class in the discriminator column, and this column is not a "field" that one would explicitly set.
  9. NotionCommotion

    Doctrine class table inheritance help

    Okay, will give it a try. As soon as I get Internet that is
  10. NotionCommotion

    Doctrine class table inheritance help

    Trying to create a model where Parent1 and Parent2 extend Grandparent, and Child1_1 and Child1_2 extend Parent1 as well as Child2_1 and Child2_2 extend Parent2. I set up my definitions: Grandparent: type: entity table: grandparent_table inheritanceType: JOINED discriminatorColumn: name: discriminator_column_grandparent type: string repositoryClass: GrandParent id: id: type: integer generator: strategy: AUTO fields: GrandParent_Item1: type: string GrandParent_Item2: type: string Parent1: type: entity table: parent_table1 extends: Grandparent inheritanceType: JOINED discriminatorColumn: name: discriminator_column_parent1 type: string id: id: associationKey: true fields: Parent1_Item1: type: string Parent1_Item2: type: string Parent2: type: entity table: parent_table2 extends: Grandparent inheritanceType: JOINED discriminatorColumn: name: discriminator_column_parent2 type: string id: id: associationKey: true fields: Parent2_Item1: type: string Parent2_Item2: type: string Child1_1: extends: Parent1 type: entity table: child1_1_table id: id: associationKey: true fields: Child1_1_Item1: type: string Child1_1_Item2: type: string Child1_2: extends: Parent1 type: entity table: child1_2_table id: id: associationKey: true fields: Child1_2_Item1: type: string Child1_2_Item2: type: string Child2_1: extends: Parent2 type: entity table: child2_1_table id: id: associationKey: true fields: Child2_1_Item1: type: string Child2_1_Item2: type: string Child2_2: extends: Parent2 type: entity table: child2_2_table id: id: associationKey: true fields: Child2_2_Item1: type: string Child2_2_Item2: type: string And then generate my entities: $ vendor/bin/doctrine orm:generate-entities -vvv src Processing entity "Child1_1" Processing entity "Child1_2" Processing entity "Child2_1" Processing entity "Child2_2" Processing entity "Grandparent" Processing entity "Parent1" Processing entity "Parent2" [OK] Entity classes generated to "/var/www/doctrine/src" Note that I needed to manually edit the Parent1 and 2 classes to extend Grandparent as well as the individual Child classes to extend their applicable Parent. Next, I create the schema: $ vendor/bin/doctrine orm:schema-tool:create --dump-sql The following SQL statements will be executed: CREATE TABLE child1_1_table (id INT NOT NULL, Child1_1_Item1 VARCHAR(255) NOT NULL, Child1_1_Item2 VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB; CREATE TABLE child1_2_table (id INT NOT NULL, Child1_2_Item1 VARCHAR(255) NOT NULL, Child1_2_Item2 VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB; CREATE TABLE child2_1_table (id INT NOT NULL, Child2_1_Item1 VARCHAR(255) NOT NULL, Child2_1_Item2 VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB; CREATE TABLE child2_2_table (id INT NOT NULL, Child2_2_Item1 VARCHAR(255) NOT NULL, Child2_2_Item2 VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB; CREATE TABLE grandparent_table (id INT AUTO_INCREMENT NOT NULL, GrandParent_Item1 VARCHAR(255) NOT NULL, GrandParent_Item2 VARCHAR(255) NOT NULL, discriminator_column_grandparent VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB; CREATE TABLE parent_table1 (id INT NOT NULL, Parent1_Item1 VARCHAR(255) NOT NULL, Parent1_Item2 VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB; CREATE TABLE parent_table2 (id INT NOT NULL, Parent2_Item1 VARCHAR(255) NOT NULL, Parent2_Item2 VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB; ALTER TABLE child1_1_table ADD CONSTRAINT FK_3445750EBF396750 FOREIGN KEY (id) REFERENCES grandparent_table (id) ON DELETE CASCADE; ALTER TABLE child1_2_table ADD CONSTRAINT FK_5AD6F93BF396750 FOREIGN KEY (id) REFERENCES grandparent_table (id) ON DELETE CASCADE; ALTER TABLE child2_1_table ADD CONSTRAINT FK_DC849CBBF396750 FOREIGN KEY (id) REFERENCES grandparent_table (id) ON DELETE CASCADE; ALTER TABLE child2_2_table ADD CONSTRAINT FK_3C205356BF396750 FOREIGN KEY (id) REFERENCES grandparent_table (id) ON DELETE CASCADE; ALTER TABLE parent_table1 ADD CONSTRAINT FK_5386E15BBF396750 FOREIGN KEY (id) REFERENCES grandparent_table (id) ON DELETE CASCADE; ALTER TABLE parent_table2 ADD CONSTRAINT FK_CA8FB0E1BF396750 FOREIGN KEY (id) REFERENCES grandparent_table (id) ON DELETE CASCADE; I see how Grandparent has discriminatorColumn discriminator_column_grandparent as expected. But why doesn't Parent1 and Parent2 have discriminatorColumn's discriminator_column_parent1 and discriminator_column_parent2? Note that I've also tried making Grandparent, Parent1, and Parent2 abstract but get the same results. I've also messed around with Mapped Superclasses, but I don't think they are applicable for my use (correct me if you think I am wrong). Thanks!
  11. Or is the ORM the only mapper?
  12. NotionCommotion

    What should be done with constraint only tables when using an ORM?

    Yes, I expect you are technically right. But if you follow their advice and use their schema-tool, I think it will.
  13. Instead of using MySQL's ENUM(), I typically create another table with the allowed values and have other tables include a FK to that table. When using an ORM (i.e. Doctrine) should I create an entity for these? It seems excessive, but if I don't, is there risk of the Doctrine deleting the tables? Thanks
  14. NotionCommotion

    Creating Doctrine inherited class

    Figured it out. Needed to put an empty class called "Room" in the directory where I was creating the classes. Don't know why I had to do so, however...
  15. NotionCommotion

    Creating Doctrine inherited class

    I am trying to class type inheritance with Doctrine. Eventually, I will be defining things using XML, but all the examples are done using doctags. I found the following and it seems to work. <?php use Doctrine\ORM\Mapping as ORM; /** * Inventory entity * * @ORM\Entity(repositoryClass="Inventory") * @ORM\Table(name="inventory") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="discriminator_column", type="string") * @ORM\DiscriminatorMap({"inventory" = "AbstractItem", "inventory_room" = "Room"}) */ abstract class AbstractItem { /** * @ORM\Id @ORM\Column(name="inventory_id") @ORM\GeneratedValue * @var int */ protected $inventory_id; /** * @ORM\Column(type="string") * @var string */ protected $category; /** * @ORM\Column(type="string") * @var string */ protected $part_number; } use Doctrine\ORM\Mapping as ORM; /** * Inventory Room entity * @ORM\Entity * @ORM\Table(name="inventory_room") */ class Room extends AbstractItem { /** * @ORM\Column(type="string") * @var string */ protected $room_type; /** * @ORM\Column(type="string") * @var string */ protected $rack_limit; But then I convert it to XML or YAML, and I get a Entity class 'Room' used in the discriminator map of class 'AbstractItem' does not exist error when trying to build the classes. I've also tried changing the type to mappedSuperclass, but no success. Any ideas? Also, what is the purpose of the DiscriminatorColumn? Thanks AbstractItem: type: entity table: inventory inheritanceType: JOINED discriminatorColumn: name: discriminator_column type: string discriminatorMap: inventory: AbstractItem inventory_room: Room repositoryClass: Inventory id: inventory_id: type: string fields: category: type: string part_number: type: string Room: type: entity table: inventory_room fields: room_type: type: string rack_limit: type: string <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity repository-class="Inventory" name="AbstractItem" table="inventory" inheritance-type="JOINED"> <discriminator-column name="discriminator_column" type="string" length="255"/> <discriminator-map> <discriminator-mapping value="inventory" class="AbstractItem"/> <discriminator-mapping value="inventory_room" class="Room"/> </discriminator-map> <id name="inventory_id" type="string" column="inventory_id"> <generator strategy="IDENTITY"/> </id> <field name="category" type="string" column="category" precision="0" scale="0" nullable="false"/> <field name="part_number" type="string" column="part_number" precision="0" scale="0" nullable="false"/> </entity> </doctrine-mapping> <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Room" table="inventory_room"> <id name="inventory_id" type="string" column="inventory_id"> <generator strategy="IDENTITY"/> </id> <field name="room_type" type="string" column="room_type" precision="0" scale="0" nullable="false"/> <field name="rack_limit" type="string" column="rack_limit" precision="0" scale="0" nullable="false"/> <field name="category" type="string" column="category" precision="0" scale="0" nullable="false"/> <field name="part_number" type="string" column="part_number" precision="0" scale="0" nullable="false"/> </entity> </doctrine-mapping>
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.