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

          People

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

            Dates

            • Created:
              Updated:
              Resolved: