improved MongoId processing and $fields to MongoModel::find()

This commit is contained in:
Anton Grebnev
2011-12-13 13:43:15 +04:00
parent 2c611dc3db
commit d1723cb87b
2 changed files with 85 additions and 10 deletions

View File

@ -13,23 +13,40 @@
abstract class MongoModel extends Model
{
protected $useMongoId = true;
public function __construct($connection = 'default')
{
parent::__construct($connection);
}
public function count($query = array(), $limit = 0, $skip = 0)
{
return $this->db->count($this->table(), $query, $limit, $skip);
}
public function find($condition = array())
public function find($condition = array(), $fields = array())
{
return $this->db->find($this->table(), $condition);
return $this->db->find($this->table(), $condition, $fields);
}
public function get($id)
{
if($this->useMongoId) {
if(! $id instanceof MongoId) {
$id = new MongoId($id);
}
}
return $this->db->get($this->table(), array('_id' => $id))->fetch();
}
public function delete($id)
{
if($this->useMongoId) {
if(! $id instanceof MongoId) {
$id = new MongoId($id);
}
}
return $this->db->delete($this->table(), array('_id' => $id));
}