X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource.pm;h=ae637e0ede50268a26b1c564561acace92a46150;hb=5d22bb74b308ad7ca28cedd1ffcfd92c106b1e68;hp=a4d31690639f7427651983eb1f99e45d66357750;hpb=8893ffd05dee05ba32bb64b4ce16ca805145aeb3;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index a4d3169..ae637e0 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -6,7 +6,6 @@ use warnings; use DBIx::Class::ResultSet; use DBIx::Class::ResultSourceHandle; -use DBIx::Class::Exception; use DBIx::Class::Carp; use Devel::GlobalDestruction; use Try::Tiny; @@ -1034,9 +1033,9 @@ exists. =over 4 -=item Arguments: \%attrs +=item Arguments: L<\%attrs|DBIx::Class::ResultSet/ATTRIBUTES> -=item Return Value: \%attrs +=item Return Value: L<\%attrs|DBIx::Class::ResultSet/ATTRIBUTES> =back @@ -1047,8 +1046,35 @@ exists. $source->resultset_attributes({ order_by => [ 'id' ] }); Store a collection of resultset attributes, that will be set on every -L produced from this result source. For a full -list see L. +L produced from this result source. + +B: C comes with its own set of issues and +bugs! While C isn't deprecated per se, its usage is +not recommended! + +Since relationships use attributes to link tables together, the "default" +attributes you set may cause unpredictable and undesired behavior. Furthermore, +the defaults cannot be turned off, so you are stuck with them. + +In most cases, what you should actually be using are project-specific methods: + + package My::Schema::ResultSet::Artist; + use base 'DBIx::Class::ResultSet'; + ... + + # BAD IDEA! + #__PACKAGE__->resultset_attributes({ prefetch => 'tracks' }); + + # GOOD IDEA! + sub with_tracks { shift->search({}, { prefetch => 'tracks' }) } + + # in your code + $schema->resultset('Artist')->with_tracks->... + +This gives you the flexibility of not using it when you don't need it. + +For more complex situations, another solution would be to use a virtual view +via L. =cut @@ -1340,8 +1366,8 @@ name. The keys/values are as specified for L_relationships->{$rel}; + #my ($self, $rel) = @_; + return shift->_relationships->{+shift}; } =head2 has_relationship @@ -1359,8 +1385,8 @@ Returns true if the source has a relationship of this name, false otherwise. =cut sub has_relationship { - my ($self, $rel) = @_; - return exists $self->_relationships->{$rel}; + #my ($self, $rel) = @_; + return exists shift->_relationships->{+shift}; } =head2 reverse_relationship_info @@ -1377,7 +1403,7 @@ Looks through all the relationships on the source this relationship points to, looking for one whose condition is the reverse of the condition on this relationship. -A common use of this is to find the name of the C relation +A common use of this is to find the name of the C relation opposing a C relation. For definition of these look in L.