1
0
mirror of synced 2025-02-03 05:49:25 +03:00
Marco Pivetta 5d12593e70 Rewrote ManyToOne SLC tests to not rely on multi-level auto-generated identifiers
Background:

Test relied on an `A->B->C` association:

 * `A#id` being `B`
 * `B#id` being `C`
 * `C#id` being an auto-generated identifier (post-insert)

This cannot work, because it breaks the UnitOfWork's identity map.
Specifically, no entries for `A` and `B` can exist in the identity map until `C` entries
are persisted (post-insert).

That means that the identifier generator for `A` and `B` should not be an "assigned"
generator, but should instead be a post-insert generator waiting for other entities
to be persisted.

We cannot fix this in ORM 2.x, but we'll need to invent something for 3.x in order to
fix that (directed graph, or caching the order of operations in the metadata graph).
2016-07-07 21:29:10 +02:00

69 lines
1.3 KiB
PHP

<?php
namespace Doctrine\Tests\Models\Cache;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table("cache_complex_action")
*/
class ComplexAction
{
const CLASSNAME = __CLASS__;
/**
* @Column
*/
public $name;
/**
* @Id
* @OneToOne(targetEntity="Action", cascade={"persist", "remove"})
* @JoinColumn(name="action1_name", referencedColumnName="name")
*/
public $action1;
/**
* @Id
* @OneToOne(targetEntity="Action", cascade={"persist", "remove"})
* @JoinColumn(name="action2_name", referencedColumnName="name")
*/
public $action2;
/**
* @OneToMany(targetEntity="Token", cascade={"persist", "remove"}, mappedBy="complexAction")
*/
public $tokens;
public function __construct(Action $action1, Action $action2, $name)
{
$this->name = $name;
$this->action1 = $action1;
$this->action2 = $action2;
$this->tokens = new ArrayCollection();
}
public function addToken(Token $token)
{
$this->tokens[] = $token;
$token->complexAction = $this;
}
/**
* @return Action
*/
public function getAction1()
{
return $this->action1;
}
/**
* @return Action
*/
public function getAction2()
{
return $this->action2;
}
}