5d12593e70
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).
96 lines
1.9 KiB
PHP
96 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Doctrine\Tests\Models\Cache;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
/**
|
|
* @Entity
|
|
* @Cache("READ_ONLY")
|
|
* @Table("cache_token")
|
|
*/
|
|
class Token
|
|
{
|
|
const CLASSNAME = __CLASS__;
|
|
|
|
/**
|
|
* @Id
|
|
* @Column(type="string")
|
|
*/
|
|
public $token;
|
|
|
|
/**
|
|
* @Column(type="date")
|
|
*/
|
|
public $expiresAt;
|
|
|
|
/**
|
|
* @OneToOne(targetEntity="Client")
|
|
*/
|
|
public $client;
|
|
|
|
/**
|
|
* @OneToMany(targetEntity="Login", cascade={"persist", "remove"}, mappedBy="token")
|
|
* @var array
|
|
*/
|
|
public $logins;
|
|
|
|
/**
|
|
* @ManyToOne(targetEntity="Action", cascade={"persist", "remove"}, inversedBy="tokens")
|
|
* @JoinColumn(name="action_name", referencedColumnName="name")
|
|
* @var array
|
|
*/
|
|
public $action;
|
|
|
|
/**
|
|
* @ManyToOne(targetEntity="ComplexAction", cascade={"persist", "remove"}, inversedBy="tokens")
|
|
* @JoinColumns({
|
|
* @JoinColumn(name="complex_action1_name", referencedColumnName="action1_name"),
|
|
* @JoinColumn(name="complex_action2_name", referencedColumnName="action2_name")
|
|
* })
|
|
* @var ComplexAction
|
|
*/
|
|
public $complexAction;
|
|
|
|
public function __construct($token, Client $client = null)
|
|
{
|
|
$this->logins = new ArrayCollection();
|
|
$this->token = $token;
|
|
$this->client = $client;
|
|
$this->expiresAt = new \DateTime(date('Y-m-d H:i:s', strtotime("+7 day")));
|
|
}
|
|
|
|
/**
|
|
* @param Login $login
|
|
*/
|
|
public function addLogin(Login $login)
|
|
{
|
|
$this->logins[] = $login;
|
|
$login->token = $this;
|
|
}
|
|
|
|
/**
|
|
* @return Client
|
|
*/
|
|
public function getClient()
|
|
{
|
|
return $this->client;
|
|
}
|
|
|
|
/**
|
|
* @return Action
|
|
*/
|
|
public function getAction()
|
|
{
|
|
return $this->action;
|
|
}
|
|
|
|
/**
|
|
* @return ComplexAction
|
|
*/
|
|
public function getComplexAction()
|
|
{
|
|
return $this->complexAction;
|
|
}
|
|
|
|
}
|