Browse Source

Fix pivot constraints on ->pivot() method of many-to-many.

Signed-off-by: Taylor Otwell <taylorotwell@gmail.com>
Taylor Otwell 12 years ago
parent
commit
57cf817de4

+ 5 - 1
laravel/database/eloquent/relationships/has_many_and_belongs_to.php

@@ -341,7 +341,11 @@ class Has_Many_And_Belongs_To extends Relationship {
 	 */
 	public function pivot()
 	{
-		return new Pivot($this->joining);
+		$key = $this->base->get_key();
+
+		$foreign = $this->foreign_key();
+
+		return with(new Pivot($this->joining))->where($foreign, '=', $key);
 	}
 
 	/**