diff --git a/artisan b/artisan index 8f7bfe4e..689b7615 100644 --- a/artisan +++ b/artisan @@ -3,7 +3,7 @@ * Laravel - A PHP Framework For Web Artisans * * @package Laravel - * @version 3.1.5 + * @version 3.1.6 * @author Taylor Otwell * @link http://laravel.com */ diff --git a/laravel/database/eloquent/query.php b/laravel/database/eloquent/query.php index aab90210..e55e6a40 100644 --- a/laravel/database/eloquent/query.php +++ b/laravel/database/eloquent/query.php @@ -1,4 +1,7 @@ -hydrate($this->model, $this->table->take(1)->get($columns, false)); + $results = $this->hydrate($this->model, $this->table->take(1)->get($columns)); return (count($results) > 0) ? head($results) : null; } @@ -63,12 +66,12 @@ public function first($columns = array('*')) * Get all of the model results for the query. * * @param array $columns - * @param bool $include + * @param bool $keyed * @return array */ - public function get($columns = array('*'), $include = true) + public function get($columns = array('*'), $keyed = true) { - return $this->hydrate($this->model, $this->table->get($columns), $include); + return $this->hydrate($this->model, $this->table->get($columns), $keyed); } /** @@ -97,9 +100,10 @@ public function paginate($per_page = null, $columns = array('*')) * * @param Model $model * @param array $results + * @param bool $keyed * @return array */ - public function hydrate($model, $results, $include = true) + public function hydrate($model, $results, $keyed = true) { $class = get_class($model); @@ -124,10 +128,20 @@ public function hydrate($model, $results, $include = true) $new->original = $new->attributes; - $models[$result[$this->model->key()]] = $new; + // Typically, the resulting models are keyed by their primary key, but it + // may be useful to not do this in some circumstances such as when we + // are eager loading a *-to-* relationships which has duplicates. + if ($keyed) + { + $models[$result[$this->model->key()]] = $new; + } + else + { + $models[] = $new; + } } - if ($include and count($results) > 0) + if (count($results) > 0) { foreach ($this->model_includes() as $relationship => $constraints) { @@ -183,12 +197,19 @@ protected function load(&$results, $relationship, $constraints) $query->table->where_nested($constraints); } - // Before matching the models, we will initialize the relationships - // to either null for single-value relationships or an array for - // the multi-value relationships as their baseline value. $query->initialize($results, $relationship); - $query->match($relationship, $results, $query->get()); + // If we're eager loading a many-to-many relationship we will disable + // the primary key indexing on the hydration since there could be + // roles shared across users and we don't want to overwrite. + if ( ! $query instanceof Has_Many_And_Belongs_To) + { + $query->match($relationship, $results, $query->get()); + } + else + { + $query->match($relationship, $results, $query->get(array('*'), false)); + } } /** diff --git a/laravel/documentation/changes.md b/laravel/documentation/changes.md index 47770a6f..e9df8928 100644 --- a/laravel/documentation/changes.md +++ b/laravel/documentation/changes.md @@ -4,6 +4,8 @@ ## Contents - [Laravel 3.2](#3.2) - [Upgrading From 3.1](#upgrade-3.2) +- [Laravel 3.1.6](#3.1.6) +- [Upgrading From 3.1.5](#upgrade-3.1.6) - [Laravel 3.1.5](#3.1.5) - [Upgrading From 3.1.4](#upgrade-3.1.5) - [Laravel 3.1.4](#3.1.4) @@ -37,6 +39,16 @@ ## Upgrading From 3.1 - Replace the **laravel** folder. + +## Laravel 3.1.6 + +- Fixes many-to-many eager loading in Eloquent. + + +## Upgrading From 3.1.5 + +- Replace the **laravel** folder. + ## Laravel 3.1.5 diff --git a/paths.php b/paths.php index 0f44dd30..c7139f9a 100644 --- a/paths.php +++ b/paths.php @@ -3,7 +3,7 @@ * Laravel - A PHP Framework For Web Artisans * * @package Laravel - * @version 3.1.5 + * @version 3.1.6 * @author Taylor Otwell * @link http://laravel.com */ diff --git a/public/index.php b/public/index.php index 56896d97..5dff5e4c 100644 --- a/public/index.php +++ b/public/index.php @@ -3,7 +3,7 @@ * Laravel - A PHP Framework For Web Artisans * * @package Laravel - * @version 3.1.5 + * @version 3.1.6 * @author Taylor Otwell * @link http://laravel.com */