From: David Schmidt Date: Mon, 23 Dec 2013 14:43:27 +0000 (+0100) Subject: Better explanation for optional fk values in rels X-Git-Tag: v0.08260~56 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=73eb813b0e8affad8fea1febdd9a495f7eb243f2;p=dbsrgits%2FDBIx-Class.git Better explanation for optional fk values in rels --- diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index 26a07ef..427b5aa 100644 --- a/lib/DBIx/Class/Relationship.pm +++ b/lib/DBIx/Class/Relationship.pm @@ -191,15 +191,16 @@ more info see L. # To retrieve the plain id if you used the ugly version: $book->get_column('author_id'); - -If the relationship is optional -- i.e. the column containing the -foreign key can be NULL -- then the belongs_to relationship does the -right thing. Thus, in the example above C<< $obj->author >> would -return C. However in this case you would probably want to set -the L attribute so that -a C is done, which makes complex resultsets involving -C or C operations work correctly. The modified -declaration is shown below: +If some of the foreign key columns are +L you probably want to set +the L attribute to +C explicitly so that SQL expressing this relation is composed with +a C (as opposed to C which is default for +L relationships). This ensures that relationship traversal +works consistently in all situations. (i.e. resultsets involving +L or +L). +The modified declaration is shown below: # in a Book class (where Author has_many Books) __PACKAGE__->belongs_to( @@ -209,7 +210,6 @@ declaration is shown below: { join_type => 'left' } ); - Cascading deletes are off by default on a C relationship. To turn them on, pass C<< cascade_delete => 1 >> in the $attr hashref.