From: Jess Robinson Date: Sun, 31 Aug 2008 12:01:25 +0000 (+0000) Subject: Added doc patches from g about cascade_delete X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2a2ab6ab326e820a2131457e3a0baaddaea46698;p=dbsrgits%2FDBIx-Class-Historic.git Added doc patches from g about cascade_delete --- diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index 8fcc313..c6960f0 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -77,7 +77,7 @@ lot later. =item .. tell DBIx::Class about relationships between my tables? -There are a vareity of relationship types that come pre-defined for +There are a variety of relationship types that come pre-defined for you to use. These are all listed in L. If you need a non-standard type, or more information, look in L. @@ -113,12 +113,19 @@ as you like. See L. Read the documentation on L. -=item .. stop DBIx::Class from attempting to cascade deletes on my has_many relationships? +=item .. stop DBIx::Class from attempting to cascade deletes on my has_many and might_have relationships? By default, DBIx::Class cascades deletes and updates across -C relationships. If your database already does this (and -that is probably better), turn it off by supplying C<< cascade_delete => 0 >> -in the relationship attributes. See L. +C and C relationships. You can disable this +behaviour on a per-relationship basis by supplying +C<< cascade_delete => 0 >> in the relationship attributes. + +The cascaded operations are performed after the requested delete or +update, so if your database has a constraint on the relationship, it +will have deleted/updated the related records or raised an exception +before DBIx::Class gets to perform the cascaded operation. + +See L. =item .. use a relationship? @@ -294,11 +301,11 @@ way to get that single row is to first run your search as usual: Then call L and ask it only to return 1 row: - ->slice(0,1) + ->slice(0) These two calls can be combined into a single statement: - ->search->(undef, { order_by => "id DESC" })->slice(0,1) + ->search->(undef, { order_by => "id DESC" })->slice(0) Why slice instead of L or L? If supported by the database, slice will use LIMIT/OFFSET to hint to the database that we diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index 5d29e69..8de8cc0 100644 --- a/lib/DBIx/Class/Relationship.pm +++ b/lib/DBIx/Class/Relationship.pm @@ -330,9 +330,12 @@ L. If you delete an object in a class with a C relationship, all the related objects will be deleted as well. To turn this behaviour off, -pass C<< cascade_delete => 0 >> in the C hashref. However, any -database-level cascade or restrict will take precedence over a -DBIx-Class-based cascading delete. +pass C<< cascade_delete => 0 >> in the C<$attr> hashref. + +The cascaded operations are performed after the requested delete or +update, so if your database has a constraint on the relationship, it +will have deleted/updated the related records or raised an exception +before DBIx::Class gets to perform the cascaded operation. If you copy an object in a class with a C relationship, all the related objects will be copied as well. To turn this behaviour off, @@ -414,8 +417,12 @@ relations that are across multiple columns. If you update or delete an object in a class with a C relationship, the related object will be updated or deleted as well. To turn off this behavior, add C<< cascade_delete => 0 >> to the C<$attr> -hashref. Any database-level update or delete constraints will override -this behavior. +hashref. + +The cascaded operations are performed after the requested delete or +update, so if your database has a constraint on the relationship, it +will have deleted/updated the related records or raised an exception +before DBIx::Class gets to perform the cascaded operation. See L for documentation on relationship methods and valid relationship attributes.