X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship.pm;h=d4926d187fb6a7cf3d35ae5731765b629bafa34e;hb=64ae166780d0cb2b9577e506da9b9b240c146d20;hp=b3f8507e7e0bc6f21768ee729d3129fa8f9a67e0;hpb=684af87666cd89229fd16c750cf1f77790e76a39;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index b3f8507..d4926d1 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. +attributes 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,6 +211,11 @@ 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. @@ -220,17 +228,17 @@ which can be assigned to relationships as well. =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 -Creates a one-to-many relationship, where the corresponding elements -of the foreign class store the calling class's primary key in one (or -more) of the foreign class columns. This relationship defaults to using -the end of this classes namespace as the foreign key in C<$related_class> -to resolve the join, unless C<$their_fk_column> specifies the foreign -key column in C<$related_class> or C specifies a reference to a -join condition hash. +Creates a one-to-many relationship where the foreign class refers to +this class's primary key. This relationship refers to zero or more +records in the foreign table (e.g. a C). This relationship +defaults to using the end of this classes namespace as the foreign key +in C<$related_class> to resolve the join, unless C<$their_fk_column> +specifies the foreign key column in C<$related_class> or C +specifies a reference to a join condition hash. =over @@ -289,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( @@ -353,7 +361,7 @@ which can be assigned to relationships as well. =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 @@ -433,11 +441,22 @@ methods and valid relationship attributes. Also see L for a L which can be assigned to relationships as well. +Note that if you supply a condition on which to join, if the column in the +current table allows nulls (i.e., has the C attribute set to a +true value), than C will warn about this because it's naughty and +you shouldn't do that. + + "might_have/has_one" must not be on columns with is_nullable set to true (MySchema::SomeClass/key) + +If you must be naughty, you can suppress the warning by setting +C environment variable to a true value. Otherwise, +you probably just want to use C. + =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 @@ -520,14 +539,23 @@ methods and valid relationship attributes. Also see L for a L which can be assigned to relationships as well. +Note that if you supply a condition on which to join, if the column in the +current table allows nulls (i.e., has the C attribute set to a +true value), than warnings might apply just as with +L. + =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