DDC-3817: hydrating many-to-many relation crashes, when trying to access auto created adder with collection (instead of single entity) #4676

Closed
opened 2026-01-22 14:47:20 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 10, 2015).

Originally assigned to: @deeky666 on GitHub.

Jira issue originally created by user stomalak:

my concern

IF Doctrine\ORM\Tools\EntityGenerator::generateEntityStubMethods (auto) generates adder, which will expect the parameter to be {color:red}target entity{color}

WHY would DoctrineModule\Stdlib\Hydrator\Strategy\AllowRemoveByValue::hydrate call this very same adder, passing an {color:red}ArrayCollection{color}

auto generated code:

public function addAnotherEntity(\NameSpace\Entity\AnotherEntity $xy)
{
    $this->anotherEntity[] = $xy;
}

outline of a (quick) workaround:

public function addAnotherEntity($xy)
{
    if($xy instanceof \NameSpace\Entity\AnotherEntity)
        $this->anotherEntity[] = $xy;
    if($xy instanceof \Doctrine\Common\Collections\ArrayCollection)
        foreach($xy as $entity)
            $this->anotherEntity[] = $entity;
}

(Same goes for removing elements from any "to-many"-collection.)

my question\s

Did I miss something on my way?
Is there any way to "enable" some kind of "multi-adding"?
Is there any chance to (further) influence that adding-part with my xml declaration?

Any advice is very welcome.

Maybe I could write my own EntityGenerator. Maybe I should use a custom Hydrator. But right now it seems to me like a little inconsistency in the library.

Originally created by @doctrinebot on GitHub (Jul 10, 2015). Originally assigned to: @deeky666 on GitHub. Jira issue originally created by user stomalak: ## my concern IF **Doctrine\ORM\Tools\EntityGenerator::generateEntityStubMethods** (auto) generates adder, which will expect the parameter to be {color:red}target entity{color} WHY would **DoctrineModule\Stdlib\Hydrator\Strategy\AllowRemoveByValue::hydrate** call this very same adder, passing an {color:red}_ArrayCollection_{color} <ins>auto generated code:</ins> ``` public function addAnotherEntity(\NameSpace\Entity\AnotherEntity $xy) { $this->anotherEntity[] = $xy; } ``` <ins>outline of a (quick) workaround:</ins> ``` public function addAnotherEntity($xy) { if($xy instanceof \NameSpace\Entity\AnotherEntity) $this->anotherEntity[] = $xy; if($xy instanceof \Doctrine\Common\Collections\ArrayCollection) foreach($xy as $entity) $this->anotherEntity[] = $entity; } ``` _(Same goes for removing elements from any "to-many"-collection.)_ ## my question\s Did I miss something on my way? Is there any way to "enable" some kind of "multi-adding"? Is there any chance to (further) influence that adding-part with my xml declaration? ### Any advice is very welcome. Maybe I could write my own **EntityGenerator*. Maybe I should use a custom *Hydrator**. But right now it seems to me like a little inconsistency in the library.
admin added the Bug label 2026-01-22 14:47:20 +01:00
admin closed this issue 2026-01-22 14:47:20 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 10, 2015):

Comment created by stomalak:

created twice (maybe a subconscious double click)

@doctrinebot commented on GitHub (Jul 10, 2015): Comment created by stomalak: created twice (maybe a subconscious double click)
Author
Owner

@doctrinebot commented on GitHub (Aug 21, 2015):

Comment created by stomalak:

I accidently set the reolution to duplicate, which might have cause that the remaining issue is no longer open (but I'm not quite shure)..

@doctrinebot commented on GitHub (Aug 21, 2015): Comment created by stomalak: I accidently set the reolution to duplicate, which might have cause that the remaining issue is no longer open (but I'm not quite shure)..
Author
Owner

@doctrinebot commented on GitHub (Aug 21, 2015):

Comment created by stomalak:

.. my fault.. I was wondering if "resolving as duplicate" might be the right way to close duplicate issues.. but it seems so

@doctrinebot commented on GitHub (Aug 21, 2015): Comment created by stomalak: .. my fault.. I was wondering if "resolving as duplicate" might be the right way to close duplicate issues.. but it seems so
Author
Owner

@doctrinebot commented on GitHub (Aug 21, 2015):

Issue was closed with resolution "Duplicate"

@doctrinebot commented on GitHub (Aug 21, 2015): Issue was closed with resolution "Duplicate"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4676