Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2632

Doctrine reverse engineer doesn't honor NOT NULL foreign keys

    Details

      Description

      In this table, the two foreign keys (which I had to downgrade from primary keys because of Doctrine and then added a separate PK named 'Id') called 'Oggetto' and 'Sistema' have been set as NOT NULL.

      
      -- -----------------------------------------------------
      -- Table `mydb`.`Composizione`
      -- -----------------------------------------------------
      DROP TABLE IF EXISTS `mydb`.`Composizione` ;
      
      CREATE  TABLE IF NOT EXISTS `mydb`.`Composizione` (
        `Id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
        `Oggetto` INT UNSIGNED NOT NULL ,
        `Sistema` INT NOT NULL ,
        INDEX `fk_Oggetto_has_Sistema_Sistema1_idx` (`Sistema` ASC) ,
        INDEX `fk_Oggetto_has_Sistema_Oggetto1_idx` (`Oggetto` ASC) ,
        PRIMARY KEY (`Id`) ,
        CONSTRAINT `fk_Oggetto_has_Sistema_Oggetto1`
          FOREIGN KEY (`Oggetto` )
          REFERENCES `mydb`.`Oggetto` (`Id` )
          ON DELETE NO ACTION
          ON UPDATE NO ACTION,
        CONSTRAINT `fk_Oggetto_has_Sistema_Sistema1`
          FOREIGN KEY (`Sistema` )
          REFERENCES `mydb`.`Sistema` (`Id` )
          ON DELETE NO ACTION
          ON UPDATE NO ACTION)
      ENGINE = InnoDB;
      

      Converting into Yaml here it is what I get.

          type: entity
          table: Composizione
          fields:
              id:
                  id: true
                  type: integer
                  unsigned: true
                  nullable: false
                  column: Id
                  generator:
                      strategy: IDENTITY
          manyToOne:
              oggetto:
                  targetEntity: Oggetto
                  cascade:      {  }
                  mappedBy:     null
                  inversedBy:   null
                  joinColumns:
                      Oggetto:
                          referencedColumnName: Id
                  orphanRemoval: false
              sistema:
                  targetEntity: Sistema
                  cascade:      {  }
                  mappedBy:     null
                  inversedBy:   null
                  joinColumns:
                      Sistema:
                          referencedColumnName: Id
                  orphanRemoval: false
          lifecycleCallbacks: {  }
      

      Basically it lost in translation the NOT NULL part.
      To make it work I had to manually add two "nullable: false" lines as I did below:

          type: entity
          table: Composizione
          fields:
              id:
                  id: true
                  type: integer
                  unsigned: true
                  nullable: false
                  column: Id
                  generator:
                      strategy: IDENTITY
          manyToOne:
              oggetto:
                  targetEntity: Oggetto
                  cascade:      {  }
                  mappedBy:     null
                  inversedBy:   null
                  joinColumns:
                      Oggetto:
                          referencedColumnName: Id
                          nullable:     false
                  orphanRemoval: false
              sistema:
                  targetEntity: Sistema
                  cascade:      {  }
                  mappedBy:     null
                  inversedBy:   null
                  joinColumns:
                      Sistema:
                          referencedColumnName: Id
                          nullable:     false
                  orphanRemoval: false
          lifecycleCallbacks: {  }
      

      Is it a bug or am I missing something?

      Regards,
      Paolo Avezzano

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Paolo Avezzano
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: