From 8a4aade8f7156bdeb00652520b80e536bfef8b8d Mon Sep 17 00:00:00 2001 From: Anahkiasen Date: Wed, 11 Jul 2012 16:27:11 +0200 Subject: [PATCH] Quick notes on Pivot tables --- laravel/documentation/database/eloquent.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/laravel/documentation/database/eloquent.md b/laravel/documentation/database/eloquent.md index bc70483b..71e3a402 100644 --- a/laravel/documentation/database/eloquent.md +++ b/laravel/documentation/database/eloquent.md @@ -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'); + } + + } + ## Inserting Related Models