Skip to content

Commit

Permalink
merged...again
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrandi committed Jun 2, 2011
2 parents 491fe27 + 5c36d63 commit 940eed8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 69 deletions.
30 changes: 7 additions & 23 deletions src/morph/Object.php
Expand Up @@ -210,6 +210,9 @@ public function save(array $options = array())
* Attempts to load the current object with data from the document id specified
* this is meant for if the _id is not necessarily an ObjectId
*
* By default Morph sets the id to be an instance of MongoId(). When searching you need
* to ensure you do the same by wrapping your id string in a MongoId object
*
* @param mixed $id
* @return Morph_Object
*/
Expand All @@ -218,19 +221,11 @@ public function loadById($id)
return Storage::instance()->fetchById($this, $id);
}

/**
* Attempts to load the current object with data from the document id specified
*
* @param mixed $id
* @return Morph_Object
*/
public function loadByObjectId($id)
{
return Storage::instance()->fetchByObjectId($this, $id);
}

/**
* Fetch multiple objects by their ids
*
* By default Morph sets the id to be an instance of MongoId(). When searching you need
* to ensure you do the same by wrapping your id string in a MongoId object
*
* @param array $ids
* @return Morph_Iterator
Expand All @@ -239,18 +234,7 @@ public function findByIds(array $ids)
{
return Storage::instance()->fetchByIds($this, $ids);
}

/**
* Fetch multiple objects by their ids
*
* @param array $ids
* @return Morph_Iterator
*/
public function findByObjectIds(array $ids)
{
return Storage::instance()->fetchByObjectIds($this, $ids);
}


/**
* Find objects by query
*
Expand Down
52 changes: 6 additions & 46 deletions src/morph/Storage.php
Expand Up @@ -94,10 +94,9 @@ public function getDatabase()
/**
* Retrieves the contents of the specified $id
* and assigns them into $object
*
* This shoudld be used if the _id is not necessarily a ObjectId()
* (or the php version, MongoId() ). You can always just wrap the id string
* in new \MongoId() as well
*
* By default Morph sets the id to be an instance of MongoId(). When searching you need
* to ensure you do the same by wrapping your id string in a MongoId object
*
* @param Morph\\Object $object
* @param mixed $id
Expand All @@ -109,28 +108,12 @@ public function fetchById(Object $object, $id)
$data = $this->db->selectCollection($object->collection())->findOne($query);
return $this->setData($object, $data);
}

/**
* Retrieves the contents of the specified $id
* and assigns them into $object
* This function is meant for if the _id is a ObjectId (the default)
*
* @param Morph\\Object $object
* @param mixed $id
* @return Morph\\Object
*/
public function fetchByObjectId(Object $object, $id)
{
if (is_string($id)) {
$id = new \MongoId($id);
}
$query = array('_id' => $id);
$data = $this->db->selectCollection($object->collection())->findOne($query);
return $this->setData($object, $data);
}

/**
* Returns all objects with an _id in $ids
*
* By default Morph sets the id to be an instance of MongoId(). When searching you need
* to ensure you do the same by wrapping your id string in a MongoId object
*
* @param Morph\\Object $object
* @param array $Ids
Expand All @@ -142,29 +125,6 @@ public function fetchByIds(Object $object, array $ids)
$query->property('_id')->in($ids);
return $this->findByQuery($object, $query);
}

/**
* Returns all objects with an _id in $ids
*
* @param Morph\\Object $object
* @param array $Ids
* @return Morph\\Iterator
*/
public function fetchObjectByIds(Object $object, array $ids)
{
$query = new Query();
$wrappedIds = array();
foreach ($ids as $id) {
if (is_string($id)) {
$wrappedIds[] = new \MongoId($id);
} else {
$wrappedIds[] = $id;
}
}

$query->property('_id')->in($ids);
return $this->findByQuery($object, $query);
}

/**
* Retrieves the contents of the specified $dbRef
Expand Down

0 comments on commit 940eed8

Please sign in to comment.