use warnings;
sub many_to_many {
- my ($class, $meth, $rel_class, $f_class) = @_;
-
- eval "require $f_class";
+ my ($class, $meth, $rel, $f_rel, $rel_attrs) = @_;
+ $rel_attrs ||= {};
{
no strict 'refs';
no warnings 'redefine';
- *{"${class}::${meth}"} =
- sub { shift->search_related($rel_class)->search_related($f_class, @_); };
+ *{"${class}::${meth}"} = sub {
+ my ($self,$cond,$attrs) = @_;
+ $self->search_related($rel)->search_related($f_rel, $cond, { %$rel_attrs, %{$attrs||{}} });
+ };
}
}