【发布时间】:2012-08-09 08:35:49
【问题描述】:
我将 HTML::FormHandler 与 Catalyst 一起使用,并且我有这个字段:
has_field 'client_account_id' => ( type => 'Select', options_method =>
\&options_account_id);
我有 3 个用外键连接的表:
clients client_accounts login
------- --------------- -----
id client_id client_account_id
现在我希望&options_account_id 仅针对某些 client_id 用client_accounts 填充client_account_id 字段。这是我到目前为止的方法:
sub options_account_id {
use my_app;
my $self = shift;
my @client_accounts = my_app->model('DB::ClientAccount')->search({
'client_id' => $client_id},
{
select => [ qw/id domain/ ], ## SELECT
})->all;
my @options;
for(@client_accounts) {
push @options, { value => $_->id, label => $_->domain};
}
return @options;
}
现在它显然不起作用,因为 $client_id 变量不存在。我的问题是,当我创建新表单时,有没有办法以某种方式传递特定的客户 ID?或者有谁知道更好的方法来做到这一点?谢谢!
【问题讨论】: