私はCatalyst でHTML::FormHandlerを使用しており、次のフィールドがあります。
has_field 'client_account_id' => ( type => 'Select', options_method =>
\&options_account_id);
外部キーに接続されている 3 つのテーブルがあります。
clients client_accounts login
------- --------------- -----
id client_id client_account_id
ここで、client_account_id フィールドに、特定のclient_id&options_account_id
の client_accounts のみを入力したいと考えています。これが私がこれまでに持っている方法です:
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 を何らかの形で渡す方法はありますか? または、これを行うためのより良い方法を知っている人はいますか? ありがとう!