$self->column_info($col)->{_filter_info} = $attrs;
my $acc = $self->column_info($col)->{accessor};
- $self->mk_group_accessors('filtered_column' => [ (defined $acc ? $acc : $col), $col]);
+ $self->mk_group_accessors('value' => [ (defined $acc ? $acc : $col), $col]);
return 1;
}
return $filtered;
}
-sub register_column {
- my ($class, $col, $info) = @_;
- my $acc = $col;
- if (exists $info->{accessor}) {
- return unless defined $info->{accessor};
- $acc = [ $info->{accessor}, $col ];
- }
- if ( exists $self->column_info($col)->{_filter_info} ) {
- $class->mk_group_accessors(value => $acc);
- } else {
- $class->mk_group_accessors(column => $acc);
- }
-}
-
1;
use warnings;
use Test::More;
-use Test::Exception;
use lib qw(t/lib);
use DBICTest;
+
+my $schema = DBICTest->init_schema();
+DBICTest::Schema::Artist->load_components('FilterColumn');
+DBICTest::Schema::Artist->filter_column(rank => {
+ filter => sub { warn "FILTERING!"; $_[1] * 2 },
+ unfilter => sub {warn "UNFILTERING!"; $_[1] / 2 },
+});
+Class::C3->reinitialize();
+
+my $artist = $schema->resultset('Artist')->create( { rank => 20 } );
+
+# this should be using the cursor directly, no inflation/processing of any sort
+my ($raw_db_rank) = $schema->resultset('Artist')
+ ->search ($artist->ident_condition)
+ ->get_column('rank')
+ ->_resultset
+ ->cursor
+ ->next;
+
+is ($raw_db_rank, 10, 'INSERT: correctly unfiltered on insertion');
+
+for my $reloaded (0, 1) {
+ my $test = $reloaded ? 'reloaded' : 'stored';
+ $artist->discard_changes if $reloaded;
+
+ is( $artist->rank , 20, "got $test filtered rank" );
+}
+
+$artist->update;
+$artist->discard_changes;
+is( $artist->rank , 20, "got filtered rank" );
+
+$artist->update ({ rank => 40 });
+($raw_db_rank) = $schema->resultset('Artist')
+ ->search ($artist->ident_condition)
+ ->get_column('rank')
+ ->_resultset
+ ->cursor
+ ->next;
+is ($raw_db_rank, 20, 'UPDATE: correctly unflitered on update');
+
+$artist->discard_changes;
+$artist->rank(40);
+ok( !$artist->is_column_changed('rank'), 'column is not dirty after setting the same value' );
+
+done_testing;