Add comment regarding foreign and associated keys in eloquent.

This commit is contained in:
Taylor Otwell 2011-07-20 09:53:05 -07:00
parent dd729886f5
commit 2b132512e8
1 changed files with 2 additions and 0 deletions

View File

@ -285,6 +285,8 @@ public function has_and_belongs_to_many($model, $table = null, $foreign_key = nu
$this->relating_table = $table; $this->relating_table = $table;
} }
// Allowing the overriding of the foreign and associated keys provides the flexibility for
// self-referential many-to-many relationships, such as a "buddy list".
$this->relating_key = (is_null($foreign_key)) ? strtolower(get_class($this)).'_id' : $foreign_key; $this->relating_key = (is_null($foreign_key)) ? strtolower(get_class($this)).'_id' : $foreign_key;
$associated_key = (is_null($associated_key)) ? strtolower($model).'_id' : $associated_key; $associated_key = (is_null($associated_key)) ? strtolower($model).'_id' : $associated_key;