cleaning up eloquent models.
This commit is contained in:
parent
b93a12209c
commit
2ac5a37291
|
@ -147,7 +147,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 = IoC::core('database')->connection(static::$connection)->table(static::table($class));
|
$model->query = IoC::container()->core('database')->connection(static::$connection)->table(static::table($class));
|
||||||
|
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,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 = IoC::core('database')->connection(static::$connection)->table(static::table($model));
|
$this->query = IoC::container()->core('database')->connection(static::$connection)->table(static::table($model));
|
||||||
|
|
||||||
if (property_exists($model, 'timestamps') and $model::$timestamps)
|
if (property_exists($model, 'timestamps') and $model::$timestamps)
|
||||||
{
|
{
|
||||||
|
@ -410,7 +410,9 @@ 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 IoC::core('database')->connection(static::$connection)->table(static::table(get_class($this)))->delete($this->id);
|
$table = static::table(get_class($this));
|
||||||
|
|
||||||
|
return IoC::container()->core('database')->connection(static::$connection)->table($table)->delete($this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -487,7 +489,7 @@ public function __call($method, $parameters)
|
||||||
|
|
||||||
// All of the aggregate and persistance functions can be passed directly to the query
|
// All of the aggregate and persistance functions can be passed directly to the query
|
||||||
// instance. For these functions, we can simply return the response of the query.
|
// instance. For these functions, we can simply return the response of the query.
|
||||||
if (in_array($method, array('insert', 'update', 'count', 'sum', 'min', 'max', 'avg')))
|
if (in_array($method, array('insert', 'update', 'abs', 'count', 'sum', 'min', 'max', 'avg')))
|
||||||
{
|
{
|
||||||
return call_user_func_array(array($this->query, $method), $parameters);
|
return call_user_func_array(array($this->query, $method), $parameters);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue