From: zby Date: Wed, 26 Nov 2008 14:24:48 +0000 (+0000) Subject: using Introspectable X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=2708ae1178c582e52969f2f1882884733c729b25;p=chaz%2Fp5-DBIx-Class-ResultSet-RecursiveUpdate using Introspectable --- diff --git a/Makefile.PL b/Makefile.PL index ca2968a..14b7077 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,6 +12,7 @@ WriteMakefile( 'Test::More' => 0, 'version' => 0, 'DBIx::Class' => 0, + 'DBIx::Class::IntrospectableM2M' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'DBIx-Class-ResultSet-RecursiveUpdate-*' }, diff --git a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm index 2dc40cb..ebdfbf8 100644 --- a/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm +++ b/lib/DBIx/Class/ResultSet/RecursiveUpdate.pm @@ -88,9 +88,14 @@ sub recursive_update { sub is_m2m { my( $self, $relation ) = @_; + my $rclass = $self->result_class; + # DBIx::Class::IntrospectableM2M + if( $rclass->can( '_m2m_metadata' ) ){ + return $rclass->_m2m_metadata->{$relation}; + } my $object = $self->new({}); if ( $object->can($relation) and - !$object->result_source->has_relationship($relation) and + !$self->result_source->has_relationship($relation) and $object->can( 'set_' . $relation) ){ return 1; @@ -100,6 +105,17 @@ sub is_m2m { sub get_m2m_source { my( $self, $relation ) = @_; + my $rclass = $self->result_class; + # DBIx::Class::IntrospectableM2M + if( $rclass->can( '_m2m_metadata' ) ){ + return $self->result_source + ->related_source( + $rclass->_m2m_metadata->{$relation}{relation} + ) + ->related_source( + $rclass->_m2m_metadata->{$relation}{foreign_relation} + ); + } my $object = $self->new({}); my $r = $object->$relation; return $r->result_source; diff --git a/t/lib/DBSchema/Result/Dvd.pm b/t/lib/DBSchema/Result/Dvd.pm index d87147c..4908080 100644 --- a/t/lib/DBSchema/Result/Dvd.pm +++ b/t/lib/DBSchema/Result/Dvd.pm @@ -9,7 +9,7 @@ use base 'DBIx::Class'; use overload '""' => sub {$_[0]->name}, fallback => 1; use lib '../../DBIx-Class-HTML-FormFu/lib/'; -__PACKAGE__->load_components('Core'); +__PACKAGE__->load_components(qw/IntrospectableM2M Core/); __PACKAGE__->table('dvd'); __PACKAGE__->add_columns( 'id' => { diff --git a/t/var/dvdzbr.db b/t/var/dvdzbr.db index 1aad3b8..3ff59f1 100644 Binary files a/t/var/dvdzbr.db and b/t/var/dvdzbr.db differ