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

Be able to set a value also used in relation


    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:


      I am using a string field for data and for an optional relation too.
      I am not using a ID because the second entity is from a third party application.

      I used two variables in my entity mapping to the same field.


      • @var string $an
      • @ORM\Column(name="an", type="string", length=20, nullable=false)
        private $an;


      • @ORM\OneToOne(targetEntity="DataLinked")
      • @ORM\JoinColumn(name="an", referencedColumnName="part")
        private $linked;

      The getter is working fine.

      The problem occurs when I create a new entity and would like to persist it.
      As the field is used twice, the value of the second variable is erasing the first value.

      At the line 525 of Doctrine\ORM\Persisters\BasicEntityPersister , I added the following test to update a null value only if there is no fieldName existing.

      foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
      if ($newVal === null) {
      if(!isset($this->_class->fieldNames[$sourceColumn]) || in_array($sourceColumn, $this->_class->identifier))

      { $result[$owningTable][$sourceColumn] = null; }

      } else if ($targetClass->containsForeignIdentifier) {

      (!isset($this->_class->fieldNames[$sourceColumn]) : Test if there is no existing fieldName
      in_array($sourceColumn, $this->_class->identifier)) : avoid skipping identifier definition because ID is listed in fieldNames!

      What do you think about that?



        There are no comments yet on this issue.


          • Assignee:
            beberlei Benjamin Eberlei
            rapotor Cedric Lahouste
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: