From 2708ae1178c582e52969f2f1882884733c729b25 Mon Sep 17 00:00:00 2001 From: zby Date: Wed, 26 Nov 2008 14:24:48 +0000 Subject: [PATCH 1/1] using Introspectable --- Makefile.PL | 1 + lib/DBIx/Class/ResultSet/RecursiveUpdate.pm | 18 +++++++++++++++++- t/lib/DBSchema/Result/Dvd.pm | 2 +- t/var/dvdzbr.db | Bin 26624 -> 26624 bytes 4 files changed, 19 insertions(+), 2 deletions(-) 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 1aad3b8639d1fc2c0e4101420ab2033122e63c01..3ff59f1999dc5104f523c8d5457ec841914a5072 100644 GIT binary patch delta 181 zcmZp;z}Rqsae|ak#xw>9kOWe!3=D<~H|m^W<~R`vG zPA<}IXF3r!`L}Kj(~0oOm3rAsCn6?4)5~Q#5xF^3pIe#fMAYP@AfTG)$!C%bSa|bK f#7v$TEHybNm~V1kGUw!gV0)$$v709b=ZgRU>~=r5 delta 181 zcmZp;z}Rqsae|akstN-HNCGKV1_lG6jXGzTIgV)pxm?GTH?c%2G98nf9Ibkf>6rXv zYqbKVV+xbks`)V;Q=I%)t%~iK5}UZaJbH=T>GqrZqV!2&hJT@|h$97T)}0 eI+G^`OHIxR=9`?C%sDwA*q-T_?&gWX`62)#fIBV# -- 2.43.0