no strict 'refs';
no warnings 'redefine';
*{"${class}::${meth}"} = sub {
- my ($self,$cond,$attrs) = @_;
- $self->search_related($rel)->search_related($f_rel, $cond, { %$rel_attrs, %{$attrs||{}} });
+ my $self = shift;
+ my $attrs = @_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {};
+ $self->search_related($rel)->search_related($f_rel, @_ > 0 ? @_ : undef, { %$rel_attrs, %$attrs });
};
}
}
# now the Helpers
DBICTest::Schema::CD->many_to_many( 'producers', 'cd_to_producer', 'producer');
+DBICTest::Schema::CD->many_to_many( 'producers_sorted', 'cd_to_producer', 'producer', { order_by => 'producer.name' });
1;
# now the Helpers
DBICTest::Schema::CD->many_to_many( 'producers', 'cd_to_producer', 'producer');
+DBICTest::Schema::CD->many_to_many( 'producers_sorted', 'cd_to_producer', 'producer', { order_by => 'producer.name' });
1;
$schema->populate('Producer', [
[ qw/producerid name/ ],
[ 1, 'Matt S Trout' ],
+ [ 2, 'Bob The Builder' ],
+ [ 3, 'Fred The Phenotype' ],
]);
$schema->populate('CD_to_Producer', [
[ qw/cd producer/ ],
[ 1, 1 ],
+ [ 1, 2 ],
+ [ 1, 3 ],
]);
1;
use strict;
use warnings;
-plan tests => 18;
+plan tests => 20;
# has_a test
my $cd = $schema->resultset("CD")->find(4);
$cd = $schema->resultset("CD")->find(1);
my @producers = $cd->producers();
is( $producers[0]->name, 'Matt S Trout', 'many_to_many ok' );
+is( $cd->producers_sorted->next->name, 'Bob The Builder', 'sorted many_to_many ok' );
+is( $cd->producers_sorted(producerid => 3)->next->name, 'Fred The Phenotype', 'sorted many_to_many with search condition ok' );
# test undirected many-to-many relationship (e.g. "related artists")
my $undir_maps = $schema->resultset("Artist")->find(1)->artist_undirected_maps;