@@ -331,7 +332,7 @@ However, you may often only want to insert a new record into the intermediate ta
...
@@ -331,7 +332,7 @@ However, you may often only want to insert a new record into the intermediate ta
$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:
@@ -427,14 +428,14 @@ If you find yourself eager loading the same models often, you may want to use **
...
@@ -427,14 +428,14 @@ If you find yourself eager loading the same models often, you may want to use **
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 @@ Sometimes you may wish to limit the attributes that are included in your model's
...
@@ -536,4 +537,13 @@ Sometimes you may wish to limit the attributes that are included in your model's
public static $hidden = array('password');
public static $hidden = array('password');
}
}
\ No newline at end of file
<aname="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.