From 00edb1db8c039ad9a7ac8badd5a32b399b3a7864 Mon Sep 17 00:00:00 2001 From: Shawn McCool Date: Wed, 3 Oct 2012 12:19:11 +0200 Subject: [PATCH] clarified table naming conventions --- laravel/documentation/database/eloquent.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/laravel/documentation/database/eloquent.md b/laravel/documentation/database/eloquent.md index 09493db0..5c36e292 100644 --- a/laravel/documentation/database/eloquent.md +++ b/laravel/documentation/database/eloquent.md @@ -245,22 +245,24 @@ ### Many-To-Many Many-to-many relationships are the most complicated of the three relationships. But don't worry, you can do this. For example, assume a User has many Roles, but a Role can also belong to many Users. Three database tables must be created to accomplish this relationship: a **users** table, a **roles** table, and a **role_user** table. The structure for each table looks like this: -**Users:** +**users:** id - INTEGER email - VARCHAR -**Roles:** +**roles:** id - INTEGER name - VARCHAR -**Role_User:** +**role_user:** id - INTEGER user_id - INTEGER role_id - INTEGER +Tables contain many records and are consequently plural. Pivot tables used in **has\_many\_and\_belongs\_to** relationships are named by combining the singular names of the two related models arranged alphabetically and concatenated them with an underscore. + Now you're ready to define the relationship on your models using the **has\_many\_and\_belongs\_to** method: class User extends Eloquent { @@ -280,7 +282,7 @@ ### Many-To-Many $roles = User::find(1)->roles; -As you may have noticed, the default name of the intermediate table is the singular names of the two related models arranged alphabetically and concatenated by an underscore. However, you are free to specify your own table name. Simply pass the table name in the second parameter to the **has\_and\_belongs\_to\_many** method: +If your table names don't follow conventions, simply pass the table name in the second parameter to the **has\_and\_belongs\_to\_many** method: class User extends Eloquent {