0

我在 Catalyst 项目中向我的 Schema 添加了新关系:

__PACKAGE__->has_many(
    'messageslog' => "myproject::Schema::Result::MessagesLog",
    sub {
    my $args = shift;
    return {
        "$args->{foreign_alias}.from" => "$args->{self_alias}.msisdn",
        "$args->{foreign_alias}.service_id" => "3",
        "$args->{foreign_alias}.date_time" => {between => ["2013-01-01 00:00:00", "2013-   01-05 23:59:59"]}
        };
    }
);

当我提出要求时:

$c->model('DB::TableClass')->search({})->hashref_array;

它完美地工作。

但我需要像这样插入搜索参数:

__PACKAGE__->has_many(
    'messageslog' => "myproject::Schema::Result::MessagesLog",
    sub {
    my $args = shift;
    return {
        "$args->{foreign_alias}.from" => "$args->{self_alias}.msisdn",
        "$args->{foreign_alias}.service_id" => "$args->{params}->{id}",
        "$args->{foreign_alias}.date_time" => {between => $args->{params}->{dates}}
        };
    }
);
$c->model('DB::TableClass')->search({}, {
    join => 'messageslog',
    -params => {id => 3, dates => ["2013-01-01 00:00:00", "2013-01-05 23:59:59"]}
})->hashref_array;

我怎样才能做到这一点?

4

1 回答 1

1

通过向 ResultSet 添加方法而不是关系,请参阅Cookbook/Predefined-searches

于 2013-02-05T16:52:01.643 回答