Skip to content

Commit

Permalink
fix copying of rows with proxied accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed Feb 7, 2014
1 parent 824472a commit e21eedd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Fix ->copy on rows with proxied ResultSet methods (thanks moltar for the
test!) (NOTE: This fix is what requires upgrading to DBIC 0.08260)

2.019002 2014-01-12 09:40:41 America/Chicago
- Pick SQL for random row selection in a cleaner way
Expand Down
2 changes: 1 addition & 1 deletion cpanfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requires 'DBIx::Class' => 0.08127;
requires 'DBIx::Class' => 0.08260;
requires 'Carp::Clan' => 6.04;
requires 'Sub::Exporter::Progressive' => 0.001006;
requires 'Lingua::EN::Inflect' => 0;
Expand Down
13 changes: 12 additions & 1 deletion lib/DBIx/Class/Helper/Row/ProxyResultSetMethod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ use warnings;

# VERSION

use base 'DBIx::Class::Helper::Row::SelfResultSet';
use base 'DBIx::Class::Helper::Row::SelfResultSet', 'Class::Accessor::Grouped';
use Sub::Name ();

use DBIx::Class::Candy::Exports;

export_methods [qw( proxy_resultset_method )];

__PACKAGE__->mk_group_accessors(inherited => '_proxy_slots');

sub proxy_resultset_method {
my ($self, $name, $attr) = @_;

my $rs_method = $attr->{resultset_method} || "with_$name";
my $slot = $attr->{slot} || $name;

$self->_proxy_slots([]) unless $self->_proxy_slots;
push @{$self->_proxy_slots}, $slot;

no strict 'refs';
my $method = $self . '::' . $name;
*{$method} = Sub::Name::subname $method, sub {
Expand All @@ -36,6 +41,12 @@ sub proxy_resultset_method {
}
}

sub copy {
delete local @{$_[0]->{_column_data}}{@{$_[0]->_proxy_slots}};

shift->next::method(@_);
}

1;

=pod
Expand Down
6 changes: 4 additions & 2 deletions t/row/proxy-resultset-method.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ subtest 'loaded data' => sub {
};

subtest 'copy result' => sub {
ok my $g3 = $g2->copy({ id => 3 }), 'Copied result.';
ok !$schema->resultset('Gnarly')->search({ id => 100 })->count,
'will not accidentally collide';
ok my $g3 = $g->copy({ id => 100 }), 'Copied result';
isa_ok $g3, 'DBIx::Class::Row';
is $g3->id, 3, 'ID = 3';
is $g3->id, 100, 'id is correctly overridden';
};

done_testing;
Expand Down

0 comments on commit e21eedd

Please sign in to comment.