Browse Source

tweak belongs to eager constraining.

Taylor Otwell 12 years ago
parent
commit
b7ac667405
1 changed files with 4 additions and 1 deletions
  1. 4 1
      laravel/database/eloquent/relationships/belongs_to.php

+ 4 - 1
laravel/database/eloquent/relationships/belongs_to.php

@@ -65,7 +65,10 @@ class Belongs_To extends Relationship {
 		// are looking for the parent of a child model in this relationship.
 		// are looking for the parent of a child model in this relationship.
 		foreach ($results as $result)
 		foreach ($results as $result)
 		{
 		{
-			$keys[] = $result->{$this->foreign_key()};
+			if ( ! is_null($key = $result->{$this->foreign_key()}))
+			{
+				$keys[] = $key;
+			}
 		}
 		}
 
 
 		$this->table->where_in($this->model->key(), array_unique($keys));
 		$this->table->where_in($this->model->key(), array_unique($keys));