Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2387

convert-mapping not working correctly with composite primary keys/foreign keys in 2.4.0-RC1

    Details

    • Type: Bug
    • Status: Awaiting Feedback
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3, 2.3.1, 2.3.2, 2.3.3, 2.3.4
    • Fix Version/s: 2.3.4
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony 2.2.0, MySQL 5.1

      Description

      (Apologies if this is somehow a Symfony-specific issue)

      I updated my application via Composer yesterday, and received Doctrine 2.4.0-RC1. After this update, generating entities has been problematic under certain circumstances.

      Here is an example table in MySQL:

      CREATE TABLE `user_email` (
        `user_id` int(10) unsigned NOT NULL COMMENT 'FK to user',
        `email` varchar(254) NOT NULL,
        `email_datasource` smallint(1) unsigned NOT NULL COMMENT 'FK to datasource_code',
        `insert_date` datetime NOT NULL,
        PRIMARY KEY (`user_id`,`email`,`email_datasource`),
        KEY `FK_UserEmail_DataSourceCode` (`email_datasource`),
        CONSTRAINT `FK_UserEmail_User` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8
      

      In Doctrine 2.3, the mapping works correctly, and you end up with a 3-part primary key, with a user property mapped to the User entity, and a datasourceCode property mapped to the DatasourceCode entity. All good.

      In 2.4, the following error is given: Single id is not allowed on composite primary key in entity UserEmail.

      Removing one of the foreign keys in the table (either to User or DatasourceCode) but keeping the primary key set to all 3 columns allows the mapping to work. But, if you then remove one of the columns from the primary key (say, email_datasource) it fails again.

        Activity

        Hide
        succinct Nicholas Van Dusen added a comment -

        Issue still present in 2.3.4 and 2.4.0-RC1

        Show
        succinct Nicholas Van Dusen added a comment - Issue still present in 2.3.4 and 2.4.0-RC1
        Hide
        guillermoespinoza Guillermo added a comment -

        The database engine I use is PostgreSQL. I'm having problems when mapping entities with composite primary keys in other tables.

        CREATE TABLE public.establecimiento
            (
              id_establecimiento integer NOT NULL,
              establecimiento character varying(100) NOT NULL,
              CONSTRAINT pk_establecimiento PRIMARY KEY (id_establecimiento )
            )
            WITH (
              OIDS=FALSE
            );
            CREATE TABLE public.establecimiento_sec
            (
              id_establecimiento_sec integer NOT NULL,
              id_establecimiento integer NOT NULL,
              det_seccion character varying(40) NOT NULL,
              plano character varying(100),
              sector_ingreso character varying(254),
              sponsor_imagen_sec character varying(96000),
              CONSTRAINT pk_establecimientos_sec PRIMARY KEY (id_establecimiento_sec , id_establecimiento ),
              CONSTRAINT fk_establec_reference_establec FOREIGN KEY (id_establecimiento)
                  REFERENCES public.establecimiento (id_establecimiento) MATCH SIMPLE
                  ON UPDATE RESTRICT ON DELETE RESTRICT
            )
            WITH (
              OIDS=TRUE
            );
            CREATE TABLE public.establecimiento_sec_plano
            (
              id_establecimiento_sec_plano integer NOT NULL,
              id_establecimiento_sec integer NOT NULL,
              id_establecimiento integer NOT NULL,
              det_plano character varying(512),
              cantidad integer NOT NULL,
              precio double precision,
              insert_charge double precision DEFAULT 0,
              descr character varying(254),
              CONSTRAINT pk_establecimiento_sec_plano PRIMARY KEY (id_establecimiento_sec_plano , id_establecimiento_sec , id_establecimiento ),
              CONSTRAINT fk_establecimiento_sec FOREIGN KEY (id_establecimiento, id_establecimiento_sec)
                  REFERENCES public.establecimiento_sec (id_establecimiento, id_establecimiento_sec) MATCH SIMPLE
                  ON UPDATE NO ACTION ON DELETE CASCADE
            )
            WITH (
              OIDS=FALSE
            );

        Defining the entity establecimientoSecPlano, $establecimientoSec variable containing the keys $establecimiento and $id_establecimiento_sec

        //Entity/EstablecimientosSecPlano

        /**
             * @ORM\Id
             * @ORM\ManyToOne(targetEntity="Ticketway\PruebaBundle\Entity\EstablecimientosSec")
             * @ORM\JoinColumns(
             *      @ORM\JoinColumn(name="id_establecimiento_sec", referencedColumnName="id_establecimiento_sec"),
             *      @ORM\JoinColumn(name="id_establecimiento", referencedColumnName="id_establecimiento")) 
             */
            private $establecimientoSec;

        //Entity/EstablecimientosSec

        /**
             * @ORM\Id
             * @ORM\ManyToOne(targetEntity="Ticketway\PruebaBundle\Entity\Establecimientos")
             * @ORM\JoinColumn(name="id_establecimiento", referencedColumnName="id_establecimiento") 
             */
            private $establecimiento;

        When executing the command doctrine: mapping: import I get the following error

        [Doctrine\ORM\Mapping\MappingException]
        It is not possible to map entity 'EstablecimientoSec' with a composite primary key as part of the
        primary key of another entity 'EstablecimientoSecPlano#idEstablecimiento'.

        Show
        guillermoespinoza Guillermo added a comment - The database engine I use is PostgreSQL . I'm having problems when mapping entities with composite primary keys in other tables. CREATE TABLE public .establecimiento ( id_establecimiento integer NOT NULL, establecimiento character varying(100) NOT NULL, CONSTRAINT pk_establecimiento PRIMARY KEY (id_establecimiento ) ) WITH ( OIDS=FALSE ); CREATE TABLE public .establecimiento_sec ( id_establecimiento_sec integer NOT NULL, id_establecimiento integer NOT NULL, det_seccion character varying(40) NOT NULL, plano character varying(100), sector_ingreso character varying(254), sponsor_imagen_sec character varying(96000), CONSTRAINT pk_establecimientos_sec PRIMARY KEY (id_establecimiento_sec , id_establecimiento ), CONSTRAINT fk_establec_reference_establec FOREIGN KEY (id_establecimiento) REFERENCES public .establecimiento (id_establecimiento) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE RESTRICT ) WITH ( OIDS=TRUE ); CREATE TABLE public .establecimiento_sec_plano ( id_establecimiento_sec_plano integer NOT NULL, id_establecimiento_sec integer NOT NULL, id_establecimiento integer NOT NULL, det_plano character varying(512), cantidad integer NOT NULL, precio double precision, insert_charge double precision DEFAULT 0, descr character varying(254), CONSTRAINT pk_establecimiento_sec_plano PRIMARY KEY (id_establecimiento_sec_plano , id_establecimiento_sec , id_establecimiento ), CONSTRAINT fk_establecimiento_sec FOREIGN KEY (id_establecimiento, id_establecimiento_sec) REFERENCES public .establecimiento_sec (id_establecimiento, id_establecimiento_sec) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE ) WITH ( OIDS=FALSE ); Defining the entity establecimientoSecPlano, $establecimientoSec variable containing the keys $establecimiento and $id_establecimiento_sec //Entity/EstablecimientosSecPlano /** * @ORM\Id * @ORM\ManyToOne(targetEntity= "Ticketway\PruebaBundle\Entity\EstablecimientosSec" ) * @ORM\JoinColumns( * @ORM\JoinColumn(name= "id_establecimiento_sec" , referencedColumnName= "id_establecimiento_sec" ), * @ORM\JoinColumn(name= "id_establecimiento" , referencedColumnName= "id_establecimiento" )) */ private $establecimientoSec; //Entity/EstablecimientosSec /** * @ORM\Id * @ORM\ManyToOne(targetEntity= "Ticketway\PruebaBundle\Entity\Establecimientos" ) * @ORM\JoinColumn(name= "id_establecimiento" , referencedColumnName= "id_establecimiento" ) */ private $establecimiento; When executing the command doctrine: mapping: import I get the following error [Doctrine\ORM\Mapping\MappingException] It is not possible to map entity 'EstablecimientoSec' with a composite primary key as part of the primary key of another entity 'EstablecimientoSecPlano#idEstablecimiento'.
        Hide
        samvdb Sam Van der Borght added a comment -

        We are having the same problem as Guillermo. Any idea on how to fix this issue?
        Does anybody know why this problem occurs? I have been looking in the code but havent had much success.

        Show
        samvdb Sam Van der Borght added a comment - We are having the same problem as Guillermo. Any idea on how to fix this issue? Does anybody know why this problem occurs? I have been looking in the code but havent had much success.
        Hide
        diegotdai Diego Antunes added a comment -

        Doesn't work for me either, composite keys aren't working in 2.3.4

        Can we get a fix for this?

        Show
        diegotdai Diego Antunes added a comment - Doesn't work for me either, composite keys aren't working in 2.3.4 Can we get a fix for this?
        Hide
        kamil Kamil Adryjanek added a comment -

        I have similar issue in my current project. Is there any chance to solve this problem in the near future?
        Composite primary/foreign keys are important...

        Show
        kamil Kamil Adryjanek added a comment - I have similar issue in my current project. Is there any chance to solve this problem in the near future? Composite primary/foreign keys are important...

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            succinct Nicholas Van Dusen
          • Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated: