Browse Source

Fix for https://github.com/laravel/laravel/issues/789

Jelle Sebreghts 12 years ago
parent
commit
ac8bd0829e
1 changed files with 21 additions and 1 deletions
  1. 21 1
      laravel/database/eloquent/model.php

+ 21 - 1
laravel/database/eloquent/model.php

@@ -253,7 +253,27 @@ abstract class Model {
 	 */
 	public function _with($includes)
 	{
-		$this->includes = (array) $includes;
+		$includes = (array) $includes;
+
+		$all_includes = array();
+
+		foreach($includes as $include)
+		{
+			$nested = explode('.', $include);
+
+			$inc = array();
+
+			foreach($nested as $relation)
+			{
+				$inc[] = $relation;
+
+				$all_includes[] = implode('.', $inc);
+			}
+
+		}
+
+		//remove duplicates and reset the array keys.
+		$this->includes = array_values(array_unique($all_includes));
 
 		return $this;
 	}