Browse Source

Merge pull request #799 from Jelle-S/develop

Eloquent - simplify eager loading
Taylor Otwell 12 years ago
parent
commit
a203a12da4
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)
 	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;
 		return $this;
 	}
 	}