X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship.pm;h=e3b812b78020f45febdbf80f4e4f2c0d00a81b52;hb=ede99b9f99bb77ceda57e42d8046d4942e8a40fa;hp=3a78bed481a6272e43b1a0d05ba36e3335faa995;hpb=b0acf5d8a931fc541137c79363e9b0447b8e7203;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index 3a78bed..e3b812b 100644 --- a/lib/DBIx/Class/Relationship.pm +++ b/lib/DBIx/Class/Relationship.pm @@ -39,6 +39,9 @@ See L for more. =head1 DESCRIPTION +The word I has a specific meaning in DBIx::Class, see +the definition in the L. + This class provides methods to set up relationships between the tables in your database model. Relationships are the most useful and powerful technique that L provides. To create efficient database queries, @@ -102,20 +105,20 @@ L. All helper methods are called similar to the following template: - __PACKAGE__->$method_name('relname', 'Foreign::Class', $cond, $attrs); - + __PACKAGE__->$method_name('relname', 'Foreign::Class', \%cond | \@cond, \%attrs); + Both C<$cond> and C<$attrs> are optional. Pass C for C<$cond> if -you want to use the default value for it, but still want to set C<$attrs>. +you want to use the default value for it, but still want to set C<\%attrs>. See L for documentation on the -attrubutes that are allowed in the C<$attrs> argument. +attrubutes that are allowed in the C<\%attrs> argument. =head2 belongs_to =over 4 -=item Arguments: $accessor_name, $related_class, $our_fk_column|\%cond|\@cond?, \%attr? +=item Arguments: $accessor_name, $related_class, $our_fk_column|\%cond|\@cond?, \%attrs? =back @@ -208,17 +211,24 @@ Cascading deletes are off by default on a C relationship. To turn them on, pass C<< cascade_delete => 1 >> in the $attr hashref. +By default, DBIC will return undef and avoid querying the database if a +C accessor is called when any part of the foreign key IS NULL. To +disable this behavior, pass C<< undef_on_null_fk => 0 >> in the C<$attr> +hashref. + NOTE: If you are used to L relationships, this is the equivalent of C. See L for documentation on relationship -methods and valid relationship attributes. +methods and valid relationship attributes. Also see L +for a L +which can be assigned to relationships as well. =head2 has_many =over 4 -=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attr? +=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attrs? =back @@ -287,7 +297,7 @@ OR condition. 'My::DBIC::Schema::Book', { 'foreign.author_id' => 'self.id' }, ); - + # OR (similar result, assuming related_class is storing our PK, in "author") # (the "author" is guessed at from "Author" in the class namespace) My::DBIC::Schema::Author->has_many( @@ -343,13 +353,15 @@ pass C<< cascade_copy => 0 >> in the C<$attr> hashref. The behaviour defaults to C<< cascade_copy => 1 >>. See L for documentation on relationship -methods and valid relationship attributes. +methods and valid relationship attributes. Also see L +for a L +which can be assigned to relationships as well. =head2 might_have =over 4 -=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attr? +=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attrs? =back @@ -425,13 +437,15 @@ 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. +methods and valid relationship attributes. Also see L +for a L +which can be assigned to relationships as well. =head2 has_one =over 4 -=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attr? +=item Arguments: $accessor_name, $related_class, $their_fk_column|\%cond|\@cond?, \%attrs? =back @@ -510,16 +524,22 @@ In the above example, each Book in the database is associated with exactly one ISBN object. See L for documentation on relationship -methods and valid relationship attributes. +methods and valid relationship attributes. Also see L +for a L +which can be assigned to relationships as well. =head2 many_to_many =over 4 -=item Arguments: $accessor_name, $link_rel_name, $foreign_rel_name, \%attr? +=item Arguments: $accessor_name, $link_rel_name, $foreign_rel_name, \%attrs? =back +C is a I which has a specific +meaning in DBIx::Class, see the definition in the +L. + C is not strictly a relationship in its own right. Instead, it is a bridge between two resultsets which provide the same kind of convenience accessors as true relationships provide. Although the accessor will return a @@ -593,7 +613,9 @@ will be created for the Role class for the C many_to_many relationship. See L for documentation on relationship -methods and valid relationship attributes. +methods and valid relationship attributes. Also see L +for a L +which can be assigned to relationships as well. =cut