improved MongoId processing and $fields to MongoModel::find()
This commit is contained in:
@ -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));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user