Skip to content

Loading…

DDC-1444: Be able to set a value also used in relation #2071

Open
doctrinebot opened this Issue · 0 comments

2 participants

@doctrinebot

Jira issue originally created by user rapotor:

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
inarray($sourceColumn, $this->class->identifier)) : avoid skipping identifier definition because ID is listed in fieldNames!

What do you think about that?

Thanks.

@beberlei beberlei was assigned by doctrinebot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.