Bernhard Graf wrote:
Am 29.01.2012 21:52, schrieb Peter Rabbitson:

It is possible, but is not yet particularly pretty. The trick is
that the coderef in question is called every time the relationship
needs to be resolved. By referencing some external package-global
you can control what the coderef will return.

like this?

__PACKAGE__->mk_group_accessors(inherited => qw(era_begin era_end));

My::Schema::Artist->has_many(
  cds_era => 'My::Schema::CD',
  sub {
    my $args = shift;

    return {
"$args->{foreign_alias}.artist" => { -ident => "$args->{self_alias}.artistid" },
      "$args->{foreign_alias}.year"   => {
         '>', __PACKAGE__->era_begin,
         '<', __PACKAGE__->era_end,
       },
    };
  }
);

...

$artist_rs->era_begin(1979);
$artist_rs->era_end(1990);
$artist_rs->search_related('cds_era')->next;



That's one way, though I would go for the more blunt:
  local $Some::Package::cond = 'foo'

Cheers

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to