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).
This commit is contained in:
parent
dbcdc1d42a
commit
5d12593e70
@ -14,13 +14,8 @@ class Action
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @GeneratedValue
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @Column
|
||||
* @Column(type="string")
|
||||
* @GeneratedValue(strategy="NONE")
|
||||
*/
|
||||
public $name;
|
||||
|
||||
|
@ -20,14 +20,14 @@ class ComplexAction
|
||||
/**
|
||||
* @Id
|
||||
* @OneToOne(targetEntity="Action", cascade={"persist", "remove"})
|
||||
* @JoinColumn(name="action1_id", referencedColumnName="id")
|
||||
* @JoinColumn(name="action1_name", referencedColumnName="name")
|
||||
*/
|
||||
public $action1;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @OneToOne(targetEntity="Action", cascade={"persist", "remove"})
|
||||
* @JoinColumn(name="action2_id", referencedColumnName="id")
|
||||
* @JoinColumn(name="action2_name", referencedColumnName="name")
|
||||
*/
|
||||
public $action2;
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Token
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="Action", cascade={"persist", "remove"}, inversedBy="tokens")
|
||||
* @JoinColumn(name="action_id", referencedColumnName="id")
|
||||
* @JoinColumn(name="action_name", referencedColumnName="name")
|
||||
* @var array
|
||||
*/
|
||||
public $action;
|
||||
@ -44,8 +44,8 @@ class Token
|
||||
/**
|
||||
* @ManyToOne(targetEntity="ComplexAction", cascade={"persist", "remove"}, inversedBy="tokens")
|
||||
* @JoinColumns({
|
||||
* @JoinColumn(name="complex_action1_id", referencedColumnName="action1_id"),
|
||||
* @JoinColumn(name="complex_action2_id", referencedColumnName="action2_id")
|
||||
* @JoinColumn(name="complex_action1_name", referencedColumnName="action1_name"),
|
||||
* @JoinColumn(name="complex_action2_name", referencedColumnName="action2_name")
|
||||
* })
|
||||
* @var ComplexAction
|
||||
*/
|
||||
|
@ -193,7 +193,7 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token));
|
||||
$this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->id));
|
||||
$this->assertFalse($this->cache->containsEntity(Token::CLASSNAME, $action->name));
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
$entity = $this->_em->find(Token::CLASSNAME, $token->token);
|
||||
@ -204,7 +204,7 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest
|
||||
$this->assertInstanceOf(Action::CLASSNAME, $entity->getAction());
|
||||
$this->assertEquals('exec', $entity->getAction()->name);
|
||||
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
|
||||
}
|
||||
|
||||
public function testPutAndLoadNonCacheableCompositeManyToOne()
|
||||
@ -231,9 +231,9 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->token));
|
||||
$this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->id));
|
||||
$this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->id));
|
||||
$this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->id));
|
||||
$this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action1->name));
|
||||
$this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action2->name));
|
||||
$this->assertFalse($this->cache->containsEntity(Action::CLASSNAME, $action3->name));
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
/**
|
||||
@ -255,8 +255,8 @@ class SecondLevelCacheManyToOneTest extends SecondLevelCacheAbstractTest
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
|
||||
$this->assertEquals('login', $entity->getComplexAction()->getAction1()->name);
|
||||
$this->assertEquals($queryCount + 2, $this->getCurrentQueryCount());
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
$this->assertEquals('rememberme', $entity->getComplexAction()->getAction2()->name);
|
||||
$this->assertEquals($queryCount + 3, $this->getCurrentQueryCount());
|
||||
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user