Merge remote-tracking branch 'laravel/develop' into develop

This commit is contained in:
Colin Viebrock
2012-03-20 22:29:26 -05:00
9 changed files with 306 additions and 47 deletions

View File

@@ -1,5 +1,6 @@
<?php namespace Laravel\Database\Eloquent;
use Laravel\Str;
use Laravel\Database;
use Laravel\Database\Eloquent\Relationships\Has_Many_And_Belongs_To;
@@ -103,17 +104,6 @@ abstract class Model {
$this->fill($attributes);
}
/**
* Set the accessible attributes for the given model.
*
* @param array $attributes
* @return void
*/
public static function accessible($attributes)
{
static::$accessible = $attributes;
}
/**
* Hydrate the model with an array of attributes.
*
@@ -157,6 +147,17 @@ abstract class Model {
return $this;
}
/**
* Set the accessible attributes for the given model.
*
* @param array $attributes
* @return void
*/
public static function accessible($attributes)
{
static::$accessible = $attributes;
}
/**
* Create a new model and store it in the database.
*
@@ -211,9 +212,7 @@ abstract class Model {
*/
public static function all()
{
$model = new static;
return $model->query()->get();
return with(new static)->query()->get();
}
/**
@@ -420,6 +419,16 @@ abstract class Model {
return ! $this->exists or $this->original !== $this->attributes;
}
/**
* Get the name of the table associated with the model.
*
* @return string
*/
public function table()
{
return static::$table ?: strtolower(Str::plural(basename(get_class($this))));
}
/**
* Get the dirty attributes for the model.
*
@@ -501,6 +510,14 @@ abstract class Model {
return $this->relationships[$key];
}
// Next we'll check if the requested key is in the array of attributes
// for the model. These are simply regular properties that typically
// correspond to a single column on the database for the model.
elseif (array_key_exists($key, $this->attributes))
{
return $this->{"get_{$key}"}();
}
// If the item is not a loaded relationship, it may be a relationship
// that hasn't been loaded yet. If it is, we will lazy load it and
// set the value of the relationship in the relationship array.