[DDC-2383] Foreign relations on primary keys don't work on more than two entities (like Foo<>Bar<>Baz) Created: 01/Apr/13 Updated: 14/Apr/13 Resolved: 14/Apr/13 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | ORM |
| Affects Version/s: | 2.3, 2.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Jacek Jędrzejewski | Assignee: | Benjamin Eberlei |
| Resolution: | Can't Fix | Votes: | 0 |
| Labels: | hydration, mapping, relations | ||
| Attachments: |
|
| Description |
|
I'm trying to accomplish something like this: For two entities (Foo<>Bar) it works as expected but adding another entity related to Bar (so it's Foo<>Bar<>Baz) ends up with this error:
Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'The column id must be mapped to a field in class Entity\Bar since it is referenced by a join column of another class.' in C:\...\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\MappingException.php:203
Stack trace:
#0 C:\...\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php(734): Doctrine\ORM\Mapping\MappingException::joinColumnMustPointToMappedField('Entity\Bar', 'id')
#1 C:\...\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php(2509): Doctrine\ORM\Persisters\BasicEntityPersister->loadOneToOneEntity(Array, Object(Entity\Bar))
#2 C:\...\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(245): Doctrine\ORM\UnitOfWork->createEntity('Entity\Bar', Array, Array)
#3 C:\...\vendor\doctrine\orm\lib\Doctrine\ORM\Internal\Hydration\ObjectHydrator.php(424): Doctrine\ORM\Internal\Hydration\Ob in C:\...\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\MappingException.php on line 203
This error appears when there are some records in the database and I want to query for example all Foos. My entites look like this: //Entity/Foo.php /** @Entity @Table(name="foos") */ class Foo { /** @Id @Column(type="integer") @GeneratedValue */ protected $id; /** @OneToOne(targetEntity="Bar", mappedBy="foo") */ protected $bar; public function getId() { return $this->id; } public function getBar() { return $this->bar; } public function setBar($bar) { $bar->setFoo($this); $this->bar = $bar; } } //Entity/Bar.php /** @Entity @Table(name="bars") */ class Bar { /** @Id @OneToOne(targetEntity="Foo", inversedBy="bar") * @JoinColumn(name="id", referencedColumnName="id") */ protected $foo; /** @OneToOne(targetEntity="Baz", mappedBy="bar") */ protected $baz; public function __construct($foo) { $this->foo = $foo; } public function getId() { return $this->getFoo()->getId(); } public function getFoo() { return $this->foo; } public function setFoo($foo) { $this->foo = $foo; } public function getBaz() { return $this->baz; } public function setBaz($baz) { $bar->setBar($this); $this->baz = $baz; } } //Entity/Baz.php /** @Entity @Table(name="bazes") */ class Baz { /** @Id @OneToOne(targetEntity="Bar", inversedBy="baz") * @JoinColumn(name="id", referencedColumnName="id") */ protected $bar; public function __construct($bar) { $this->bar = $bar; } public function getId() { return $this->getBar()->getId(); } public function getBar() { return $this->bar; } public function setBar($bar) { $this->bar = $bar; } } And fails on
$fooRepository = $em->getRepository('Entity\Foo');
$foos = $fooRepository->findAll();
|
| Comments |
| Comment by Jacek Jędrzejewski [ 01/Apr/13 ] |
|
Attaching a test case which results in two exceptions - while creating the schema and while fetching entities. |
| Comment by Benjamin Eberlei [ 14/Apr/13 ] |
|
This is sadly a restriction of the foreign keys as primary key feature. Due to the architecture of shared nothing Metadata instances we cannot validate this at mapping compile time, only at runtime, thus leading to this error. |
[DDC-2199] Yaml driver does not take into account field @Version attribute Created: 14/Dec/12 Updated: 16/Dec/12 Resolved: 16/Dec/12 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | Mapping Drivers |
| Affects Version/s: | Git Master |
| Fix Version/s: | 2.3.2 |
| Security Level: | All |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Georgy Galakhov | Assignee: | Benjamin Eberlei |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | mapping, yaml | ||
| Description |
|
Even if field has version: true attribute, Yaml driver does not set class metadata isVersioned and versionField properties. As a result optimistic lock cannot be used. |
| Comments |
| Comment by Benjamin Eberlei [ 16/Dec/12 ] |
|
Fixed |
[DDC-2189] Bidirectional one-to-many association with Class Table Inheritance do not work Created: 06/Dec/12 Updated: 24/Dec/12 Resolved: 24/Dec/12 |
|
| Status: | Resolved |
| Project: | Doctrine 2 - ORM |
| Component/s: | ORM |
| Affects Version/s: | 2.3 |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Bug | Priority: | Major |
| Reporter: | Ro | Assignee: | Benjamin Eberlei |
| Resolution: | Invalid | Votes: | 0 |
| Labels: | Mapping | ||
| Environment: |
PHP 5.4.8 (cli) (built: Oct 18 2012 13:02:07) Fedora Linux 17 mysql Ver 14.14 Distrib 5.5.28, for Linux (x86_64) using readline 5.1 |
||
| Attachments: |
|
| Description |
|
Bidirectional one-to-many association with Class Table Inheritance does not work. Example. Entity Box; BoxItem has ManyToOne to Box; Validation Error: |
| Comments |
| Comment by Marco Pivetta [ 06/Dec/12 ] |
|
Not a blocker |
| Comment by Marco Pivetta [ 06/Dec/12 ] |
|
Ro this looks invalid to me.
/**
* @MayToOne(targetEntity="Asmuo", inversedBy="items")
* @JoinColumn(name="box_id", referencedColumnName="id")
*/
protected $box;
What's `Asmuo`? |
| Comment by Ro [ 06/Dec/12 ] |
|
Sorry, I did post wrong file BoxItem, my mistake, but the bug persists. |
| Comment by Marco Pivetta [ 06/Dec/12 ] |
|
Just checked on my side with attached entities (changed some namespaces, see latest attached files) and everything's fine. |
| Comment by Benjamin Eberlei [ 24/Dec/12 ] |
|
Error caused by Invalid mapping |