خرید بک لینک

Vote count: 0

Using ORM

$timer = new Timer();
$em->persist($timer);
print $timer->getId(); //blank - not yet set
$em->flush($timer);
print $timer->getId(); //prints ID of newly inserted record

Actual ORM Code (Doctrine)

public function persist($entity)
{
    if ( ! is_object($entity)) {
        throw ORMInvalidArgumentException::invalidObject('EntityManager#persist()' , $entity);
    }

    $this->errorIfClosed();

    $this->unitOfWork->persist($entity);
}

Question

How does Doctrine insert insert_id into the Entity, when the ORM's code above has no "pass by reference" directive?

I.e. normally I'd expect something like this:

public function persist(&$entity)
{
    ...
}

to indicate that the entity will be modified (with insert_id) during the persist process. But there is nothing of the sort. Nevertheless, Entity is populated with insert_id magically.

How does that happen exactly?

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 6 خرداد 1395 ساعت: 3:39

صفحه بندی