mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-842: spl_object_hash tries to get hash from array - fails #1043
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Oct 19, 2010).
Jira issue originally created by user sebastian.hoitz:
I have a model which looks like this:
When I try to persist my object to the database, Doctrine causes this error:
I assume that this might happen, because of the Class B holding one Class C, and Class A also holding some Class C instances.
Those are, in some cases, the same. So when a new Class B is added, together with a new Class C, this new Class C is also added to Class A.
And somehow internally the already persisted Class C (Class B is getting persisted first) transforms the Class C instance into an array, and Doctrine can't save it anymore.
This is my guess of what happens. When I skip adding all the Class C instances to Class A, I don't get this error.
@doctrinebot commented on GitHub (Oct 19, 2010):
Comment created by mjh_ca:
Do you get the same error if the collections are defined as ArrayCollections instead of PHP arrays ? Not sure if it is supported to use pure PHP arrays for collections.
See [http://www.doctrine-project.org/projects/orm/2.0/docs/reference/association-mapping/en#collections]
@doctrinebot commented on GitHub (Oct 21, 2010):
Comment created by sebastian.hoitz:
I change the definition inside of my constructor method to ArrayCollection.
It's just that I write array() when I define the properties to that it's easier for the developers to tell which properties are collections or not.
So they actually are ArrayCollections.
@doctrinebot commented on GitHub (Oct 22, 2010):
Comment created by shurakai:
Please post your entity mappings and some code.
It would be highly appreciated if you could also provide a test case so that we can confirm easily. Thank you!
@doctrinebot commented on GitHub (Oct 24, 2010):
Comment created by sebastian.hoitz:
This was a very stupid issue on my side which I wasn't even thinking about:
I have my own "ModelCollection" class in which I store my models. This class extends Doctrines ArrayCollection class and overwrites the toArray function. It changed its behavior so that the toArray was called recursively also on all child elements.
This caused the PersistentCollection to return an array on the getInsertDiff method.
Long story short: Maybe we should think about making the toArray method on the ArrayCollection class final, since Doctrines ORM relies on its behavior.
@doctrinebot commented on GitHub (Oct 24, 2010):
Issue was closed with resolution "Invalid"