在客户端应用程序中,我有一个DBIx::Class模型'Todo‘,它可以使用多对多关系链接到许多其他模型。我知道,由于业务逻辑,1个且只有1个外来模型与其关联。我想在我的查询中使用以下命令来获取该模型:
my $objects = $c->model('DB')->resultset('Todo')->search($myFilter,{
prefetch => \@relations # contains all possible relations
});就像文档声明的那样,DBIx::Class::ResultSource对此发出警告:
DBIx::Class::ResultSet::next(): Prefetching multiple has_many rels accountbalances_todos and accounts_todos at top level will explode the number of row objects retrievable via ->next or ->all. Use at your own risk. at /media/psf/projects/.../Controller/Todo.pm line 117谁能告诉我如何避免这个错误而不去编辑DBIx::Class::ResultSource本身?我看不到其他方法来做我想要做的事情,并且想要防止应用程序在日志中转储大量警告。我尝试过摆弄@CARP_NOT和$Carp::Internal,但无法让Carp跳过此警告(有关此警告的文档充其量也是很少的)
如果有人能帮我,那就太好了,谢谢
发布于 2012-06-24 20:15:00
您可以覆盖对警告信号的默认处理,以捕获并忽略此特定警告:
$SIG{__WARN__} = sub {
my $warn_msg = $_[0];
if ( $warn_msg =~ m/Prefetching multiple has_many rels accountbalances_todos/ ) {
# do nothing
} else {
warn $warn_msg;
}
};或者,如果你愿意,
$SIG{__WARN__} = sub {
warn $_[0] unless $_[0] =~ m/Prefetching multiple has_many rels accountbalances_todos/
};发布于 2012-06-24 21:34:31
DBIx::Class使用来自DBIx::Class::Carp模块的carp()函数,而不是来自Carp。所以@CARP_NOT和$Carp::Internal无法工作。而不是Use $SIG{__WARN__}。
https://stackoverflow.com/questions/11177286
复制相似问题