X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship%2FBase.pm;h=6c6475417b227dac331c8db5e5f9e38d31b0ef09;hb=ff04fc51d1d8006d10a0629dd7b58dad0ec1a06a;hp=d6563f4ca7643bd9a18df3ca2bc43c4b4c5afb84;hpb=fd323bf1046faa7de5a8c985268d80ec5b703361;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index d6563f4..6c64754 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -3,8 +3,9 @@ package DBIx::Class::Relationship::Base; use strict; use warnings; -use Scalar::Util (); use base qw/DBIx::Class/; + +use Scalar::Util qw/weaken blessed/; use Try::Tiny; use namespace::clean; @@ -92,7 +93,11 @@ Explicitly specifies the type of join to use in the relationship. Any SQL join type is valid, e.g. C or C. It will be placed in the SQL command immediately before C. -=item proxy +=item proxy =E $column | \@columns | \%column + +=over 4 + +=item \@columns An arrayref containing a list of accessors in the foreign class to create in the main class. If, for example, you do the following: @@ -108,6 +113,25 @@ Then, assuming MyDB::Schema::LinerNotes has an accessor named notes, you can do: $cd->notes('Notes go here'); # set notes -- LinerNotes object is # created if it doesn't exist +=item \%column + +A hashref where each key is the accessor you want installed in the main class, +and its value is the name of the original in the fireign class. + + MyDB::Schema::Track->belongs_to( cd => 'DBICTest::Schema::CD', 'cd', { + proxy => { cd_title => 'title' }, + }); + +This will create an accessor named C on the C<$track> row object. + +=back + +NOTE: you can pass a nested struct too, for example: + + MyDB::Schema::Track->belongs_to( cd => 'DBICTest::Schema::CD', 'cd', { + proxy => [ 'year', { cd_title => 'title' } ], + }); + =item accessor Specifies the type of accessor that should be created for the relationship. @@ -255,10 +279,10 @@ sub related_resultset { foreach my $rev_rel (keys %$reverse) { if ($reverse->{$rev_rel}{attrs}{accessor} && $reverse->{$rev_rel}{attrs}{accessor} eq 'multi') { $attrs->{related_objects}{$rev_rel} = [ $self ]; - Scalar::Util::weaken($attrs->{related_object}{$rev_rel}[0]); + weaken $attrs->{related_object}{$rev_rel}[0]; } else { $attrs->{related_objects}{$rev_rel} = $self; - Scalar::Util::weaken($attrs->{related_object}{$rev_rel}); + weaken $attrs->{related_object}{$rev_rel}; } } } @@ -459,7 +483,7 @@ sub set_from_related { if (defined $f_obj) { my $f_class = $rel_info->{class}; $self->throw_exception( "Object $f_obj isn't a ".$f_class ) - unless Scalar::Util::blessed($f_obj) and $f_obj->isa($f_class); + unless blessed $f_obj and $f_obj->isa($f_class); } $self->set_columns( $self->result_source->_resolve_condition(