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

Closed
opened 2026-01-22 13:26:51 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Oct 21, 2011).

Originally assigned to: @beberlei on GitHub.

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

What do you think about that?

Thanks.

Originally created by @doctrinebot on GitHub (Oct 21, 2011). Originally assigned to: @beberlei on GitHub. 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 in_array($sourceColumn, $this->_class->identifier)) : avoid skipping identifier definition because ID is listed in fieldNames! What do you think about that? Thanks.
admin added the Improvement label 2026-01-22 13:26:52 +01:00
admin closed this issue 2026-01-22 13:26:52 +01:00
Author
Owner

@beberlei commented on GitHub (Feb 16, 2020):

Not supported use case to re-use the same column for multiple things.

@beberlei commented on GitHub (Feb 16, 2020): Not supported use case to re-use the same column for multiple things.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1812