Browse Source

revert eloquent back to 3.2.3

Taylor Otwell 12 years ago
parent
commit
1203473469

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

@@ -255,22 +255,7 @@ abstract class Model {
 	 */
 	 */
 	public function _with($includes)
 	public function _with($includes)
 	{
 	{
-		$includes = (array) $includes;
-
-		$this->includes = array();
-
-		foreach ($includes as $relationship => $constraints)
-		{
-			// When eager loading relationships, constraints may be set on the eager
-			// load definition; however, is none are set, we need to swap the key
-			// and the value of the array since there are no constraints.
-			if (is_numeric($relationship))
-			{
-				list($relationship, $constraints) = array($constraints, null);
-			}
-
-			$this->includes[$relationship] = $constraints;
-		}
+		$this->includes = (array) $includes;
 
 
 		return $this;
 		return $this;
 	}
 	}
@@ -533,7 +518,7 @@ abstract class Model {
 
 
 		foreach ($this->attributes as $key => $value)
 		foreach ($this->attributes as $key => $value)
 		{
 		{
-			if ( ! array_key_exists($key, $this->original) or $value !== $this->original[$key])
+			if ( ! isset($this->original[$key]) or $value !== $this->original[$key])
 			{
 			{
 				$dirty[$key] = $value;
 				$dirty[$key] = $value;
 			}
 			}
@@ -567,7 +552,6 @@ abstract class Model {
 	 * Get a given attribute from the model.
 	 * Get a given attribute from the model.
 	 *
 	 *
 	 * @param  string  $key
 	 * @param  string  $key
-	 * @return mixed
 	 */
 	 */
 	public function get_attribute($key)
 	public function get_attribute($key)
 	{
 	{
@@ -723,7 +707,7 @@ abstract class Model {
 	{
 	{
 		foreach (array('attributes', 'relationships') as $source)
 		foreach (array('attributes', 'relationships') as $source)
 		{
 		{
-			if (array_key_exists($key, $this->$source)) return !is_null($this->$source[$key]);
+			if (array_key_exists($key, $this->$source)) return true;
 		}
 		}
 		
 		
 		if (method_exists($this, $key)) return true;
 		if (method_exists($this, $key)) return true;
@@ -754,7 +738,7 @@ abstract class Model {
 	{
 	{
 		$meta = array('key', 'table', 'connection', 'sequence', 'per_page', 'timestamps');
 		$meta = array('key', 'table', 'connection', 'sequence', 'per_page', 'timestamps');
 
 
-		// If the method is actually the name of a static property on the model, we'll
+		// If the method is actually the name of a static property on the model we'll
 		// return the value of the static property. This makes it convenient for
 		// return the value of the static property. This makes it convenient for
 		// relationships to access these values off of the instances.
 		// relationships to access these values off of the instances.
 		if (in_array($method, $meta))
 		if (in_array($method, $meta))
@@ -764,7 +748,7 @@ abstract class Model {
 
 
 		$underscored = array('with', 'find');
 		$underscored = array('with', 'find');
 
 
-		// Some methods need to be accessed both statically and non-statically so we'll
+		// Some methods need to be accessed both staticly and non-staticly so we'll
 		// keep underscored methods of those methods and intercept calls to them
 		// keep underscored methods of those methods and intercept calls to them
 		// here so they can be called either way on the model instance.
 		// here so they can be called either way on the model instance.
 		if (in_array($method, $underscored))
 		if (in_array($method, $underscored))

+ 2 - 3
laravel/database/eloquent/relationships/belongs_to.php

@@ -79,9 +79,8 @@ class Belongs_To extends Relationship {
 	/**
 	/**
 	 * Match eagerly loaded child models to their parent models.
 	 * Match eagerly loaded child models to their parent models.
 	 *
 	 *
-	 * @param  string  $relationship
-	 * @param  array   $children
-	 * @param  array   $parents
+	 * @param  array  $children
+	 * @param  array  $parents
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function match($relationship, &$children, $parents)
 	public function match($relationship, &$children, $parents)

+ 2 - 3
laravel/database/eloquent/relationships/has_many.php

@@ -83,9 +83,8 @@ class Has_Many extends Has_One_Or_Many {
 	/**
 	/**
 	 * Match eagerly loaded child models to their parent models.
 	 * Match eagerly loaded child models to their parent models.
 	 *
 	 *
-	 * @param  string  $relationship
-	 * @param  array   $parents
-	 * @param  array   $children
+	 * @param  array  $parents
+	 * @param  array  $children
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function match($relationship, &$parents, $children)
 	public function match($relationship, &$parents, $children)

+ 11 - 21
laravel/database/eloquent/relationships/has_many_and_belongs_to.php

@@ -44,7 +44,7 @@ class Has_Many_And_Belongs_To extends Relationship {
 		$this->joining = $table ?: $this->joining($model, $associated);
 		$this->joining = $table ?: $this->joining($model, $associated);
 
 
 		// If the Pivot table is timestamped, we'll set the timestamp columns to be
 		// If the Pivot table is timestamped, we'll set the timestamp columns to be
-		// fetched when the pivot table models are fetched by the developer, or else
+		// fetched when the pivot table models are fetched by the developer else
 		// the ID will be the only "extra" column fetched in by default.
 		// the ID will be the only "extra" column fetched in by default.
 		if (Pivot::$timestamps)
 		if (Pivot::$timestamps)
 		{
 		{
@@ -61,8 +61,6 @@ class Has_Many_And_Belongs_To extends Relationship {
 	 *
 	 *
 	 * By default, the name is the models sorted and joined with underscores.
 	 * By default, the name is the models sorted and joined with underscores.
 	 *
 	 *
-	 * @param  Model   $model
-	 * @param  string  $associated
 	 * @return string
 	 * @return string
 	 */
 	 */
 	protected function joining($model, $associated)
 	protected function joining($model, $associated)
@@ -88,7 +86,7 @@ class Has_Many_And_Belongs_To extends Relationship {
 	 * Insert a new record into the joining table of the association.
 	 * Insert a new record into the joining table of the association.
 	 *
 	 *
 	 * @param  int    $id
 	 * @param  int    $id
-	 * @param  array  $attributes
+	 * @param  array  $joining
 	 * @return bool
 	 * @return bool
 	 */
 	 */
 	public function attach($id, $attributes = array())
 	public function attach($id, $attributes = array())
@@ -133,7 +131,7 @@ class Has_Many_And_Belongs_To extends Relationship {
 		}
 		}
 
 
 		// Next we will take the difference of the current and given IDs and detach
 		// Next we will take the difference of the current and given IDs and detach
-		// all of the entities that exist in the current array but are not in
+		// all of the entities that exists in the current array but are not in
 		// the array of IDs given to the method, finishing the sync.
 		// the array of IDs given to the method, finishing the sync.
 		$detach = array_diff($current, $ids);
 		$detach = array_diff($current, $ids);
 
 
@@ -319,30 +317,22 @@ class Has_Many_And_Belongs_To extends Relationship {
 	/**
 	/**
 	 * Match eagerly loaded child models to their parent models.
 	 * Match eagerly loaded child models to their parent models.
 	 *
 	 *
-	 * @param  string  $relationship
-	 * @param  array   $parents
-	 * @param  array   $children
+	 * @param  array  $parents
+	 * @param  array  $children
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function match($relationship, &$parents, $children)
 	public function match($relationship, &$parents, $children)
 	{
 	{
 		$foreign = $this->foreign_key();
 		$foreign = $this->foreign_key();
 
 
-		$dictionary = array();
-
-		foreach ($children as $child)
-		{
-			$dictionary[$child->pivot->$foreign][] = $child;
-		}
-
 		foreach ($parents as &$parent)
 		foreach ($parents as &$parent)
 		{
 		{
-			$parent_key = $parent->get_key();
-
-			if (isset($dictionary[$parent_key]))
+			$matching = array_filter($children, function($v) use (&$parent, $foreign)
 			{
 			{
-				$parent->relationships[$relationship] = $dictionary[$parent_key];
-			}
+				return $v->pivot->$foreign == $parent->get_key();
+			});
+
+			$parent->relationships[$relationship] = array_values($matching);
 		}
 		}
 	}
 	}
 
 
@@ -386,7 +376,7 @@ class Has_Many_And_Belongs_To extends Relationship {
 	/**
 	/**
 	 * Set the columns on the joining table that should be fetched.
 	 * Set the columns on the joining table that should be fetched.
 	 *
 	 *
-	 * @param  array         $columns
+	 * @param  array         $column
 	 * @return Relationship
 	 * @return Relationship
 	 */
 	 */
 	public function with($columns)
 	public function with($columns)

+ 2 - 3
laravel/database/eloquent/relationships/has_one.php

@@ -30,9 +30,8 @@ class Has_One extends Has_One_Or_Many {
 	/**
 	/**
 	 * Match eagerly loaded child models to their parent models.
 	 * Match eagerly loaded child models to their parent models.
 	 *
 	 *
-	 * @param  string  $relationship
-	 * @param  array   $parents
-	 * @param  array   $children
+	 * @param  array  $parents
+	 * @param  array  $children
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function match($relationship, &$parents, $children)
 	public function match($relationship, &$parents, $children)