Skip to content

Commit

Permalink
Merge branch 'devel' into release/1.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
canni committed Jan 26, 2011
2 parents 19007a8 + 3f390f8 commit 85f3721
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions extra/EMongoPartialDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function isPartial()
*/
public function getLoadedFields()
{
return $this->_loadedFields;
return $this->_partial ? $this->_loadedFields : array();
}

/**
Expand All @@ -52,10 +52,10 @@ public function getLoadedFields()
*/
public function getUnloadedFields()
{
return array_diff(
return $this->_partial ? array_diff(
$this->_loadedFields,
$this->attributeNames()
);
) : array();
}

/**
Expand All @@ -75,6 +75,28 @@ public function __get($name)
return parent::__get($name);
}

/**
* If user explicitly sets the unloaded embedded field, consider it as an loaded one, if model is partially loaded
* @see EMongoEmbeddedDocument::__set()
*/
public function __set($name, $value)
{
$return = parent::__set($name, $value);

if($this->_partial && !in_array($name, $this->_loadedFields))
{
$this->_loadedFields[] = $name;

if(count($this->_loadedFields) === count($this->attributeNames()))
{
$this->_partial = false;
$this->loadedFields = null;
}
}

return $return;
}

/**
* Loads additional, previously unloaded attributes
* to this document.
Expand Down

0 comments on commit 85f3721

Please sign in to comment.