mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-1397: Accesing a OneToMany relation with Child Classes and OneToOne relations. #1749
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 (Sep 29, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user gbrunacci:
I am facing a small issue on Doctrine 2 that causes OneToOne relation needed to be part of the parent class. The error occurs when doing $content->getVersions() but not when doing $em->find("Model\Lantern\Content\Version", $id). The error message is:
Error replication:
Simply by having a look at the model we can see what's causing the Bug, will avoid class annotations to make it simpler:
As you can see, Article::$summary targets Summary::$version, but Summary::$version targets Version::$summary. This in OOP is valid as Version is contained inside Article, so doing a downcasting will get Article::summary.
The reason I believe why using $em->find works is that $em->find already knows which child class is before doing map, and relations works fine.
On the other hand, when doing $content->getVersions(), Content::$versions targets Version, and looks like Doctrine does not resolve which child class it before mapping OneToOne relationshipg.
This bug doesn't occur with OneToMany or ManyToMany relationships.
@doctrinebot commented on GitHub (Sep 29, 2011):
Comment created by gbrunacci:
A side but useful note: when I move @OneToOne relation to the parent class Version, The error doesn't happen.
@doctrinebot commented on GitHub (Oct 4, 2011):
Comment created by @guilhermeblanco:
Should be the Summary::$version pointing to Article::$summary.
Your mapping is wrong conceptually in OOP, because you're referring a non-existing property of Version ($summary is only part of Article).
Please fix the issue and check out if the error still persist.
@doctrinebot commented on GitHub (Oct 15, 2011):
Comment created by @beberlei:
The mapping is wrong as guilherme said,
@doctrinebot commented on GitHub (Oct 15, 2011):
Issue was closed with resolution "Invalid"