mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-1439: Saving many to many association with composed keys. #1805
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 20, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user vigor_bg:
I have a problem with saving many to many realtion. My entities are.
So in the middle table that i keep the keys from the other 2 i need to save only key1 and key3. And key2 need to be ignored.
But when i try to save instead of saving the proper values it try to save the value for key2 instead of the value of key1 in the middle table.
After some debuging i found that in Doctrine\ORM\Persisters\ManyToManyPersister in the private function _collectJoinTableColumnParameters lies the problem.
Instead of taking the key by the name you are doing array_pop. And you are making a check for composite keys but you presume that bouth of the keys will be
in the middle table, but that is not the case for me.
The quick fix that i did was to remove the current check for isComposite and get the keys like we are in the isComposite case always.
Tanks in advance for the great work.
Have a nice day!
@doctrinebot commented on GitHub (Oct 28, 2011):
Comment created by @beberlei:
This kind of mapping is not supported right now, the CLI tool "orm:validate-schema" should throw a compile time error on it as well.
I am not sure if just changing that line is enough for this to work, or if there are other obstacles as well.
@doctrinebot commented on GitHub (Oct 28, 2011):
Comment created by vigor_bg:
well that is the code so you can see what exactly i have removed
@doctrinebot commented on GitHub (Oct 28, 2011):
Comment created by @beberlei:
i did find that already and also think its a good change to do sometihng along this lines (there is a better solution), however i dont knöow if that is even enough to get your use-case working across the whole ORM. We have zero test-cases for this kind of mapping, so i cannot guarantee you this works at all. This is why the orm:validate-schema gives you an error for this aswell (since some commits ago, this was missing earlier).
@doctrinebot commented on GitHub (Oct 31, 2011):
Comment created by @beberlei:
I checked the code again, this mapping is invalid. You have to define all id columns as join columns or otherwise the core will explode somewhere.
Since i cannot know and guarantee where it works and where it doesnt the SchemaValidator throws an exception about this problem. I added tests to master and 2.1.x that this mapping error is indeed given as an error.
@doctrinebot commented on GitHub (Oct 31, 2011):
Issue was closed with resolution "Fixed"
@doctrinebot commented on GitHub (Oct 31, 2011):
Comment created by @beberlei:
sorry, i coudlnt fix it in 2.1.x, just in 2.2