use service location in eloquent models to resolve the database manager.

This commit is contained in:
Taylor Otwell 2011-09-02 20:10:35 -05:00
parent 6281c8c360
commit 7518088ffe
1 changed files with 3 additions and 4 deletions

View File

@ -2,7 +2,6 @@
use Laravel\Str; use Laravel\Str;
use Laravel\Inflector; use Laravel\Inflector;
use Laravel\Database\Manager;
abstract class Model { abstract class Model {
@ -133,7 +132,7 @@ public static function query($class)
// Since this method is only used for instantiating models for querying // Since this method is only used for instantiating models for querying
// purposes, we will go ahead and set the Query instance on the model. // purposes, we will go ahead and set the Query instance on the model.
$model->query = Manager::connection(static::$connection)->table(static::table($class)); $model->query = IoC::resolve('laravel.database')->connection(static::$connection)->table(static::table($class));
return $model; return $model;
} }
@ -347,7 +346,7 @@ public function save()
// Since the model was instantiated using "new", a query instance has not been set. // Since the model was instantiated using "new", a query instance has not been set.
// Only models being used for querying have their query instances set by default. // Only models being used for querying have their query instances set by default.
$this->query = Manager::connection(static::$connection)->table(static::table($model)); $this->query = IoC::resolve('laravel.database')->connection(static::$connection)->table(static::table($model));
if (property_exists($model, 'timestamps') and $model::$timestamps) if (property_exists($model, 'timestamps') and $model::$timestamps)
{ {
@ -396,7 +395,7 @@ public function delete($id = null)
// delete statement to the query instance. // delete statement to the query instance.
if ( ! $this->exists) return $this->query->delete(); if ( ! $this->exists) return $this->query->delete();
return Manager::connection(static::$connection)->table(static::table(get_class($this)))->delete($this->id); return IoC::resolve('laravel.database')->connection(static::$connection)->table(static::table(get_class($this)))->delete($this->id);
} }
/** /**