setModel() public method

Set a model instance for the model being queried.
public setModel ( Model $model )
$model Model
 /**
  * Get a new query builder for the model's table.
  *
  * @return \Illuminate\Database\Eloquent\Builder;
  */
 public function newRawQuery()
 {
     $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;
 }
Example #2
0
 /**
  * Overriding newQuery() to the custom PostBuilder with some intereting methods
  * 
  * @param bool $excludeDeleted
  * @return Corcel\PostBuilder
  */
 public function newQuery($excludeDeleted = true)
 {
     $builder = new Builder($this->newBaseQueryBuilder());
     $builder->setModel($this);
     $builder->leftJoin('wp_term_taxonomy', 'wp_terms.term_id', '=', 'wp_term_taxonomy.term_id')->where('wp_term_taxonomy.taxonomy', '=', 'category')->select('wp_terms.*');
     if ($excludeDeleted and $this->softDelete) {
         $builder->whereNull($this->getQualifiedDeletedAtColumn());
     }
     return $builder;
 }
Example #3
0
 /**
  * Set a model instance for the model being queried.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  * @return $this 
  * @static 
  */
 public static function setModel($model)
 {
     return \Illuminate\Database\Eloquent\Builder::setModel($model);
 }
Example #4
0
 /**
  * Get a new query builder for the model's table.
  *
  * @param  bool  $excludeDeleted
  * @return \Illuminate\Database\Eloquent\Builder|static
  */
 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->whereNull($this->getQualifiedDeletedAtColumn());
     }
     return $builder;
 }
Example #5
0
 /**
  * We automatically select all columns for the model to simplify some logic around select/addSelect
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  * @return $this
  */
 public function setModel(Model $model)
 {
     parent::setModel($model);
     $this->select('*');
     return $this;
 }