Skip to content
Browse files

correcting typo and adding Morph_Object::findOneByQuery()

git-svn-id: http://mongodb-morph.googlecode.com/svn/trunk@127 406649b4-5d4b-11de-8abc-d1c337b90d21
  • Loading branch information...
1 parent d193709 commit d16ba094b936db42558ab1cd1c104f94e3de2365 XirisR committed Feb 9, 2010
View
7 mongodb-morph/src/Morph/Collection.php
@@ -218,4 +218,11 @@ private function checkType($object){
throw new RuntimeException('object of type' . get_class($object) . ' does not extend ' . $this->PermissableType);
}
}
+
+ public function __toString()
+ {
+ $class = $this->PermissableType;
+ $count = $this->count();
+ return "Morph_Collection($class) Count: $count";
+ }
}
View
2 mongodb-morph/src/Morph/Iterator.php
@@ -65,7 +65,7 @@ public function toCollection()
{
$collection = new Morph_Collection();
- $collection->setPermissableType($this->type);
+ $collection->setPermissableType(get_class($this->type));
$collection->setTotalCount($this->totalCount());
$this->rewind();
View
11 mongodb-morph/src/Morph/Object.php
@@ -239,6 +239,17 @@ public function findByQuery(Morph_Query $query)
return Morph_Storage::instance()->findByQuery($this, $query);
}
+ /**
+ * Finds one object by query
+ *
+ * @param Morph_Query $query
+ * @return Morph_Object
+ */
+ public function findOneByQuery(Morph_Query $query)
+ {
+ return Morph_Storage::instance()->findOneByQuery($this, $query);
+ }
+
// ***************** //
// UTILITY FUNCTIONS //
View
21 mongodb-morph/src/Morph/Storage.php
@@ -209,6 +209,27 @@ public function findByQuery(Morph_Object $object, Morph_Query $query = null)
}
/**
+ * Finds one object matching the passed in query
+ *
+ * @param Morph_Object $object
+ * @param Morph_Query $query
+ * @return Morph_Object
+ */
+ public function findOneByQuery(Morph_Object $object, Morph_Query $query = null)
+ {
+ $result = null;
+ $class = get_class($object);
+
+ $query = (is_null($query)) ? new Morph_Query() : $query;
+ $data = $this->Db->selectCollection($object->collection())->findOne($query->getRawQuery());
+ if (!empty($data)) {
+ $result = new $class;
+ $result->__setData($data, Morph_Enum::STATE_CLEAN);
+ }
+ return $result;
+ }
+
+ /**
* Fetches a object representing a file in MongoDB
*
* @param mixed $id

0 comments on commit d16ba09

Please sign in to comment.
Something went wrong with that request. Please try again.