LMongo\Eloquent\Builder::withTrashed PHP Method

withTrashed() public method

Include the soft deleted models in the results.
public withTrashed ( ) : LMongo\Eloquent\Builder
return LMongo\Eloquent\Builder
    public function withTrashed()
    {
        $column = $this->model->getQualifiedDeletedAtColumn();
        foreach ($this->query->wheres as $key => $where) {
            // If the where clause is a soft delete date constraint, we will remove it from
            // the query and reset the keys on the wheres. This allows this developer to
            // include deleted model in a relationship result set that is lazy loaded.
            if ($this->isSoftDeleteConstraint($where, $column)) {
                unset($this->query->wheres[$key]);
                $this->query->wheres = array_values($this->query->wheres);
            }
        }
        return $this;
    }

Usage Example

 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));
 }
All Usage Examples Of LMongo\Eloquent\Builder::withTrashed