DDC-1939: Trying to save ManyToMany relatrionship #2445

Closed
opened 2026-01-22 13:53:23 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 23, 2012).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user yokoloko:

When i try to save a many to many relationship i have to following error

Fatal error: Call to a member function getOwner() on a non-object in Doctrine/ORM/Persisters/ManyToManyPersister.php on line 181

It tries to call getOwner on the following array ($mapping)

array(19) {
["fieldName"] => string(10) "privileges"
["joinTable"] => array(4) {
["name"] => string(36) "fsbackend.user_mch_account_privilege"
["schema"] => NULL
["joinColumns"] => array(2) {
[0] => array(6) {
["name"] => string(13) "mch_accountid"
["referencedColumnName"] => string(13) "mch_accountid"
["unique"] => bool(false)
["nullable"] => bool(true)
["onDelete"] => NULL
["columnDefinition"] => NULL
}
[1] => array(6) {
["name"] => string(3) "uid"
["referencedColumnName"] => string(3) "uid"
["unique"] => bool(false)
["nullable"] => bool(true)
["onDelete"] => NULL
["columnDefinition"] => NULL
}
}
["inverseJoinColumns"] => array(1) {
[0] => array(6) {
["name"] => string(10) "resourceid"
["referencedColumnName"] => string(10) "resourceid"
["unique"] => bool(false)
["nullable"] => bool(true)
["onDelete"] => NULL
["columnDefinition"] => NULL
}
}
}
["targetEntity"] => string(21) "Entity\User\Privilege"
["mappedBy"] => NULL
["inversedBy"] => NULL
["cascade"] => array(0) {
}
["indexBy"] => string(10) "resourceid"
["fetch"] => int(2)
["type"] => int(8)
["isOwningSide"] => bool(true)
["sourceEntity"] => string(26) "Entity\Merchant\Membership"
["isCascadeRemove"] => bool(false)
["isCascadePersist"] => bool(false)
["isCascadeRefresh"] => bool(false)
["isCascadeMerge"] => bool(false)
["isCascadeDetach"] => bool(false)
["relationToSourceKeyColumns"] => array(2) {
["mch_accountid"] => string(13) "mch_accountid"
["uid"] => string(3) "uid"
}
["joinTableColumns"] => array(3) {
[0] => string(13) "mch_accountid"
[1] => string(3) "uid"
[2] => string(10) "resourceid"
}
["relationToTargetKeyColumns"] => array(1) {
["resourceid"] => string(10) "resourceid"
}
}

Originally created by @doctrinebot on GitHub (Jul 23, 2012). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user yokoloko: When i try to save a many to many relationship i have to following error Fatal error: Call to a member function getOwner() on a non-object in Doctrine/ORM/Persisters/ManyToManyPersister.php on line 181 It tries to call getOwner on the following array ($mapping) array(19) { ["fieldName"] => string(10) "privileges" ["joinTable"] => array(4) { ["name"] => string(36) "fsbackend.user_mch_account_privilege" ["schema"] => NULL ["joinColumns"] => array(2) { [0] => array(6) { ["name"] => string(13) "mch_accountid" ["referencedColumnName"] => string(13) "mch_accountid" ["unique"] => bool(false) ["nullable"] => bool(true) ["onDelete"] => NULL ["columnDefinition"] => NULL } [1] => array(6) { ["name"] => string(3) "uid" ["referencedColumnName"] => string(3) "uid" ["unique"] => bool(false) ["nullable"] => bool(true) ["onDelete"] => NULL ["columnDefinition"] => NULL } } ["inverseJoinColumns"] => array(1) { [0] => array(6) { ["name"] => string(10) "resourceid" ["referencedColumnName"] => string(10) "resourceid" ["unique"] => bool(false) ["nullable"] => bool(true) ["onDelete"] => NULL ["columnDefinition"] => NULL } } } ["targetEntity"] => string(21) "Entity\User\Privilege" ["mappedBy"] => NULL ["inversedBy"] => NULL ["cascade"] => array(0) { } ["indexBy"] => string(10) "resourceid" ["fetch"] => int(2) ["type"] => int(8) ["isOwningSide"] => bool(true) ["sourceEntity"] => string(26) "Entity\Merchant\Membership" ["isCascadeRemove"] => bool(false) ["isCascadePersist"] => bool(false) ["isCascadeRefresh"] => bool(false) ["isCascadeMerge"] => bool(false) ["isCascadeDetach"] => bool(false) ["relationToSourceKeyColumns"] => array(2) { ["mch_accountid"] => string(13) "mch_accountid" ["uid"] => string(3) "uid" } ["joinTableColumns"] => array(3) { [0] => string(13) "mch_accountid" [1] => string(3) "uid" [2] => string(10) "resourceid" } ["relationToTargetKeyColumns"] => array(1) { ["resourceid"] => string(10) "resourceid" } }
admin added the Bug label 2026-01-22 13:53:23 +01:00
admin closed this issue 2026-01-22 13:53:25 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 23, 2012):

Comment created by @ocramius:

Can you try to replace your cache with an ArrayCache and see if the problem may come from there?
It would also be interesting to see your bootstrap code and the code you use to interact with the collection.

@doctrinebot commented on GitHub (Jul 23, 2012): Comment created by @ocramius: Can you try to replace your cache with an `ArrayCache` and see if the problem may come from there? It would also be interesting to see your bootstrap code and the code you use to interact with the collection.
Author
Owner

@doctrinebot commented on GitHub (Jul 23, 2012):

Comment created by yokoloko:

I'm already using an ArrayCache for my cache.

Also for my bootstrap I'm using this implementation of it : https://github.com/guilhermeblanco/ZendFramework1-Doctrine2.

Here is how i interact with the collection.

$collection->clear();
foreach ($values as $value) {
$collection->add(
$this->_em->getReference(
'Entity\User\Privilege',
$value
));}

... Later on ...
... I have an entity $userAccount with many memberships set to Cascade persist, ....
... and on the membership entity relationship i have my collection ...

$this->_em->persist($userAccount);
$this->_em->flush();

@doctrinebot commented on GitHub (Jul 23, 2012): Comment created by yokoloko: I'm already using an ArrayCache for my cache. Also for my bootstrap I'm using this implementation of it : https://github.com/guilhermeblanco/ZendFramework1-Doctrine2. Here is how i interact with the collection. `$collection->clear();` `foreach ($values as $value) {` `$collection->add(` `$this->_em->getReference(` `'Entity\User\Privilege',` `$value` `));`} ... Later on ... ... I have an entity $userAccount with many memberships set to Cascade persist, .... ... and on the membership entity relationship i have my collection ... `$this->_em->persist($userAccount);` `$this->_em->flush();`
Author
Owner

@doctrinebot commented on GitHub (Jul 24, 2012):

Comment created by yokoloko:

I don't know if it helps but it works if I replace $mapping with $coll on line 181 :

$sourceClass = $this->*em->getClassMetadata(get*class($mapping->getOwner()));

Replaced by :

$sourceClass = $this->*em->getClassMetadata(get*class($coll->getOwner()));

@doctrinebot commented on GitHub (Jul 24, 2012): Comment created by yokoloko: I don't know if it helps but it works if I replace $mapping with $coll on line 181 : `$sourceClass = $this->*em->getClassMetadata(get*class($mapping->getOwner()));` Replaced by : `$sourceClass = $this->*em->getClassMetadata(get*class($coll->getOwner()));`
Author
Owner

@doctrinebot commented on GitHub (Jul 24, 2012):

Comment created by @ocramius:

Looks like code coming from the (removed) AssociationMapping class. The fix seems also to be valid. I'm patching this.

@doctrinebot commented on GitHub (Jul 24, 2012): Comment created by @ocramius: Looks like code coming from the (removed) AssociationMapping class. The fix seems also to be valid. I'm patching this.
Author
Owner

@doctrinebot commented on GitHub (Jul 24, 2012):

Comment created by @ocramius:

Nevermind, I don't think this needs a test. It is just something overlooked during a refactoring. Being handled at DDC-1941

@doctrinebot commented on GitHub (Jul 24, 2012): Comment created by @ocramius: Nevermind, I don't think this needs a test. It is just something overlooked during a refactoring. Being handled at [DDC-1941](http://www.doctrine-project.org/jira/browse/DDC-1941)
Author
Owner

@doctrinebot commented on GitHub (Jul 24, 2012):

Comment created by @ocramius:

Could you please provide the models anyway? It would be interesting to see why the test suite doesn't cover that part :)
Thank you!

@doctrinebot commented on GitHub (Jul 24, 2012): Comment created by @ocramius: Could you please provide the models anyway? It would be interesting to see why the test suite doesn't cover that part :) Thank you!
Author
Owner

@doctrinebot commented on GitHub (Jul 24, 2012):

Comment created by yokoloko:

Ok I attached it. Tell me if you need more informations i didn't upload the full models. But just the parts i thought were relevant.

@doctrinebot commented on GitHub (Jul 24, 2012): Comment created by yokoloko: Ok I attached it. Tell me if you need more informations i didn't upload the full models. But just the parts i thought were relevant.
Author
Owner

@doctrinebot commented on GitHub (Jul 29, 2012):

Comment created by @beberlei:

Fixed and applied to 2.2.3 and 2.3

@doctrinebot commented on GitHub (Jul 29, 2012): Comment created by @beberlei: Fixed and applied to 2.2.3 and 2.3
Author
Owner

@doctrinebot commented on GitHub (Jul 29, 2012):

Issue was closed with resolution "Fixed"

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

No dependencies set.

Reference: doctrine/archived-orm#2445