public function testWithDeletedProperlyRemovesDeletedClause() { $builder = new LMongo\Eloquent\Builder(new LMongo\Query\Builder(m::mock('LMongo\\Connection'))); $model = m::mock('LMongo\\Eloquent\\Model'); $model->shouldReceive('getCollection')->once()->andReturn(''); $model->shouldReceive('getQualifiedDeletedAtColumn')->once()->andReturn('deleted_at'); $builder->setModel($model); $builder->getQuery()->where('updated_at', null); $builder->getQuery()->where('deleted_at', null); $builder->getQuery()->where('foo_bar', null); $builder->withTrashed(); $this->assertEquals(2, count($builder->getQuery()->wheres)); }
/** * Get a new query builder for the model's table. * * @param bool $excludeDeleted * @return \LMongo\Eloquent\Builder */ public function newQuery($excludeDeleted = true) { $builder = new Builder($this->newBaseQueryBuilder()); // Once we have the query builders, we will set the model instances so the // builder can easily access any information it may need from the model // while it is constructing and executing various queries against it. $builder->setModel($this)->with($this->with); if ($excludeDeleted and $this->softDelete) { $builder->where($this->getQualifiedDeletedAtColumn(), null); } return $builder; }
/** * Get a new query builder for the model's table. * * @return LMongo\Eloquent\Builder */ public function newQuery() { $builder = new Builder($this->newBaseQueryBuilder()); // Once we have the query builders, we will set the model instances so the // builder can easily access any information it may need from the model // while it is constructing and executing various queries against it. $builder->setModel($this)->with($this->with); return $builder; }