Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1587

Foreign key as Primary does not work as intended

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Invalid
    • Affects Version/s: 2.1.5
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Hi,

      In first time, sorry for my bad english.

      The feature Foreign key as Primary does not work as intended.

      The CLI tool report an error on validating mapping:
      The referenced column name 'pk_agent' does not have a corresponding field with this column name on the class 'BddP\Model\Entity\Sd\Contact'.

      If I run the application, many features works: querying, entity population.
      But for persist a new Agent without associated entities for OneToOne; the ORM report :
      PDOException: SQLSTATE[23502]: Not null violation on "pk" column

      And If I comment all OneToOne, the persist work.

      Thank you in advance for your response.

      Agent.php
      /**
       * @Entity(repositoryClass="BddP\Model\Entity\Repository\Sd\Agent")
       * @Table(name="agent")
       */
      class Agent extends AEntity
      {
          /**
           * Agent ID
           * @var int
           *
           * @Id
           * @GeneratedValue
           * @Column(name="pk", type="integer", nullable=false)
           */
          private $pk;
          /**
           * @var BddP\Model\Entity\Sd\Contact
           *
           * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Contact", cascade={"remove,merge,detach"}, mappedBy="agent")
           * @JoinColumn(name="pk", referencedColumnName="pk_agent")
           */
          private $contact;
      
          [...]
      
      }
      
      
      Contact.php
      /**
       * @Table(name="contact")
       */
      class Contact extends AEntity
      {
          /**
           * The agent
           * @var BddP\Model\Entity\Sd\Agent
           *
           * @Id
           * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Agent", inversedBy="contact")
           * @JoinColumn(name="pk_agent", referencedColumnName="pk")
           */
          private $agent;
      
          [...]
      
      }
      
      
      1. AgentDdc1587.php
        3 kB
        Presteus
      2. IdentifierDdc1587.php
        3 kB
        Presteus

        Activity

        Presteus created issue -
        Presteus made changes -
        Field Original Value New Value
        Description
        Hi,

        In first time, sorry for my bad english.

        The feature Foreign key as Primary does not work as intended.

        The CLI tool report an error on validating mapping:
        *The referenced column name 'pk_agent' does not have a corresponding field with this column name on the class 'BddP\Model\Entity\Sd\Contact'.*

        If I run the application, many features works: querying, entity population.
        But for persist a new Agent without associated entities for OneToOne; the ORM report :
        *PDOException: SQLSTATE[23502]: Not null violation on "pk" column*

        And If I comment all OneToOne, the persist work.

        Thank you in advance for your response.

        {code:title=Agent.php|borderStyle=solid}
        /**
         * @Entity(repositoryClass="BddP\Model\Entity\Repository\Sd\Agent")
         * @Table(name="agent")
         */
        class Agent extends AEntity
        {
            /**
             * Agent ID
             * @var int
             *
             * @Id
             * @GeneratedValue
             * @Column(name="pk", type="integer", nullable=false)
             */
            private $pk;
            /**
             * @var BddP\Model\Entity\Sd\Contact
             *
             * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Contact", cascade={"remove,merge,detach"}, mappedBy="agent")
             * @JoinColumn(name="pk", referencedColumnName="pk_agent")
             */
            private $contact;

            [...]

        }

        {code}

        {code:title=Contact.php|borderStyle=solid}
        /**
         * @Table(name="contact")
         */
        class Contact extends AEntity
        {
            /**
             * The agent
             * @var BddP\Model\Entity\Sd\Agent
             *
             * @Id
             * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Agent", inversedBy="contact")
             * @JoinColumn(name="pk_agent", referencedColumnName="pk")
             */
            private $agent;

            [...]

        }

        {code}
        Hi,

        In first time, sorry for my bad english.

        The feature Foreign key as Primary does not work as intended.

        The CLI tool report an error on validating mapping:
        *The referenced column name 'pk_agent' does not have a corresponding field with this column name on the class 'BddP\Model\Entity\Sd\Contact'.*

        If I run the application, many features works: querying, entity population.
        But for persist a new Agent without associated entities for OneToOne; the ORM report :
        *PDOException: SQLSTATE[23502]: Not null violation on "pk" column*

        And If I comment all OneToOne, the persist work.

        Thank you in advance for your response.

        {code:title=Agent.php|borderStyle=solid}
        /**
         * @Entity(repositoryClass="BddP\Model\Entity\Repository\Sd\Agent")
         * @Table(name="agent")
         */
        class Agent extends AEntity
        {
            /**
             * Agent ID
             * @var int
             *
             * @Id
             * @GeneratedValue
             * @Column(name="pk", type="integer", nullable=false)
             */
            private $pk;
            /**
             * @var BddP\Model\Entity\Sd\Contact
             *
             * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Contact", cascade={"remove,merge,detach"}, mappedBy="agent")
             * @JoinColumn(name="pk", referencedColumnName="pk_agent")
             */
            private $contact;

            [...]

        }

        {code}

        {code:title=Contact.php|borderStyle=solid}
        /**
         * @Table(name="contact")
         */
        class Contact extends AEntity
        {
            /**
             * The agent
             * @var BddP\Model\Entity\Sd\Agent
             *
             * @Id
             * @OneToOne(targetEntity="BddP\Model\Entity\Sd\Agent", inversedBy="contact")
             * @JoinColumn(name="pk_agent", referencedColumnName="pk")
             */
            private $agent;

            [...]

        }

        {code}
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]
        Presteus made changes -
        Resolution Invalid [ 6 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Presteus made changes -
        Attachment AgentDdc1587.php [ 11150 ]
        Attachment IdentifierDdc1587.php [ 11151 ]
        Guilherme Blanco made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Assignee Benjamin Eberlei [ beberlei ] Guilherme Blanco [ guilhermeblanco ]
        Resolution Invalid [ 6 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13341 ] jira-feedback [ 15185 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15185 ] jira-feedback2 [ 17049 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17049 ] jira-feedback3 [ 19302 ]

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Presteus
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: