Merge pull request #938 from Anahkiasen/develop
Added quick notes on Pivot tables
This commit is contained in:
@@ -244,6 +244,7 @@ Many-to-many relationships are the most complicated of the three relationships.
|
|||||||
|
|
||||||
**Roles_Users:**
|
**Roles_Users:**
|
||||||
|
|
||||||
|
id - INTEGER
|
||||||
user_id - INTEGER
|
user_id - INTEGER
|
||||||
role_id - INTEGER
|
role_id - INTEGER
|
||||||
|
|
||||||
@@ -277,6 +278,17 @@ As you may have noticed, the default name of the intermediate table is the singu
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
<a name="inserting-related-models"></a>
|
||||||
## Inserting Related Models
|
## Inserting Related Models
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user