I'm using HTML::FormHandler with Catalyst and I have this field:
has_field 'client_account_id' => ( type => 'Select', options_method =>
\&options_account_id);
I have 3 tables that are connected with foreign keys:
clients client_accounts login
------- --------------- -----
id client_id client_account_id
Now I want &options_account_id
to fill the client_account_id field with client_accounts only for a certain client_id. Here is the method I have so far:
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;
}
Now it doesn't work obviously because the $client_id variable does not exist. My question is, is there a way to somehow pass in the certain client id when I create the new form? Or does anyone know of a better way to do this? Thanks!