Someone else can re-word this, but a easy-to-find paragraph on deleteing Eloquent models seemed missing.

Signed-off-by: Colin Viebrock <colin@viebrock.ca>
This commit is contained in:
Colin Viebrock 2012-07-23 14:29:29 -05:00
parent 1db67d47a3
commit c60a58ff26
1 changed files with 14 additions and 4 deletions

View File

@ -15,6 +15,7 @@ ## Contents
- [Setter & Getter Methods](#getter-and-setter-methods) - [Setter & Getter Methods](#getter-and-setter-methods)
- [Mass-Assignment](#mass-assignment) - [Mass-Assignment](#mass-assignment)
- [Converting Models To Arrays](#to-array) - [Converting Models To Arrays](#to-array)
- [Deleting Models](#delete)
<a name="the-basics"></a> <a name="the-basics"></a>
## The Basics ## The Basics
@ -331,7 +332,7 @@ ### Inserting Related Models (Many-To-Many)
$user->roles()->attach($role_id); $user->roles()->attach($role_id);
It's also possible to attach data for fields in the intermediate table (pivot table), to do this add a second array variable to the attach command containing the data you want to attach: It's also possible to attach data for fields in the intermediate table (pivot table), to do this add a second array variable to the attach command containing the data you want to attach:
$user->roles()->attach($role_id, array('expires' => $expires)); $user->roles()->attach($role_id, array('expires' => $expires));
<a name="sync-method"></a> <a name="sync-method"></a>
@ -427,14 +428,14 @@ ## Eager Loading
class Book extends Eloquent { class Book extends Eloquent {
public $includes = array('author'); public $includes = array('author');
public function author() public function author()
{ {
return $this->belongs_to('Author'); return $this->belongs_to('Author');
} }
} }
**$includes** takes the same arguments that **with** takes. The following is now eagerly loaded. **$includes** takes the same arguments that **with** takes. The following is now eagerly loaded.
foreach (Book::all() as $book) foreach (Book::all() as $book)
@ -536,4 +537,13 @@ #### Excluding attributes from the array:
public static $hidden = array('password'); public static $hidden = array('password');
} }
<a name="delete"></a>
## Deleting Models
Because Eloquent inherits all the features and methods of Fluent queries, deleting models is a snap:
$author->delete();
Note, however, than this won't delete any related models (e.g. all the author's Book models will still exist), unless you have set up [foreign keys](/docs/database/schema#foreign-keys) and cascading deletes.