Example #1
0
 /**
  * Create a new relation instance.
  *
  * @param  LMongo\Eloquent\Builder
  * @param  LMongo\Eloquent\Model
  * @return void
  */
 public function __construct(Builder $query, Model $parent)
 {
     $this->query = $query;
     $this->parent = $parent;
     $this->related = $query->getModel();
     $this->addConstraints();
 }
 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));
 }
Example #3
0
 /**
  * Get the base query builder driving the Eloquent builder.
  *
  * @return \LMongo\Query\Builder
  */
 public function getBaseQuery()
 {
     return $this->query->getQuery();
 }
Example #4
0
 /**
  * Insert the given attributes and set the ID on the model.
  *
  * @param  \LMongo\Eloquent\Builder  $query
  * @param  array  $attributes
  * @return void
  */
 protected function insertAndSetId($query, $attributes)
 {
     $keyName = $this->getKeyName();
     $this->setAttribute($keyName, $query->save($attributes));
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * Set a model instance for the model being queried.
  *
  * @param  \LMongo\Eloquent\Model  $model
  * @return \LMongo\Eloquent\Builder
  */
 public function setModel(Model $model)
 {
     $this->model = $model;
     $this->query->collection($model->getCollection());
     return $this;
 }
Example #7
0
 /**
  * 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;
 }