Quick notes on Pivot tables

This commit is contained in:
Anahkiasen 2012-07-11 16:27:11 +02:00
parent 1879e6575a
commit 8a4aade8f7
1 changed files with 12 additions and 0 deletions

View File

@ -244,6 +244,7 @@ ### Many-To-Many
**Roles_Users:**
id - INTEGER
user_id - INTEGER
role_id - INTEGER
@ -277,6 +278,17 @@ ### Many-To-Many
}
By default only certain fields from the pivot table will be returned (the two **id** fields, and the timestamps). If your pivot table contains additional columns, you can fetch them too by using the **with()** method :
class User extends Eloquent {
public function roles()
{
return $this->has_many_and_belongs_to('Role', 'user_roles')->with('column');
}
}
<a name="inserting-related-models"></a>
## Inserting Related Models