Skip to content

Commit

Permalink
make non entity objects work
Browse files Browse the repository at this point in the history
  • Loading branch information
uwej711 committed Mar 25, 2015
1 parent 4482420 commit 1776b18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
13 changes: 13 additions & 0 deletions Alice/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ public function merge($obj)
{
return $this->om->merge($obj);
}

/**
* Check for managed objects
*
* @param $obj
*
* @return bool
*/
public function contains($obj)
{
return $this->om->contains($obj);
}

}
17 changes: 5 additions & 12 deletions Alice/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function setObjectManager(ObjectManager $manager)
$newReferences = array();
foreach ($this->references as $name => $reference) {
// Don't merge value objects, e.g. Doctrine embeddables
if ($this->hasIdentity($reference)) {
if ($this->persister->contains($reference)) {
$reference = $this->persister->merge($reference);
}

Expand Down Expand Up @@ -106,7 +106,9 @@ public function load(array $files)
}

foreach ($loader->getReferences() as $name => $obj) {
$this->persister->detach($obj);
if ($this->persister->contains($obj)) {
$this->persister->detach($obj);
}
$this->references->set($name, $obj);
}

Expand Down Expand Up @@ -178,14 +180,5 @@ private function persist($objects)
}
}

/**
* Returns whether the passed in object has "identity" as defined by Doctrine.
*
* @param mixed $reference
* @return bool
*/
private function hasIdentity($reference)
{
return count($this->objectManager->getClassMetadata(get_class($reference))->getIdentifier()) > 0;
}

}

0 comments on commit 1776b18

Please sign in to comment.