[Catalyst] Re: difficulty in assigning an array to a stash

Matt S Trout dbix-class at trout.me.uk
Mon Nov 12 17:35:06 GMT 2007

On Mon, Nov 12, 2007 at 08:48:22PM +0530, jagdish eashwar wrote:
> Hi,
> Thank you for all the responses. I must admit that I never realised
> that what I was getting was not the last value but the number of
> elements in the array. Anyway, in the course of my experimentation, I
> did make some half hearted attempts with '$c->stash->{myoptions} =
> \@options;' yesterday, but instead of the options, I was getting a
> list of 'myleave::Model::myleavedb::txn_mdl=HASH(some_number) in the
> tt2 template. When I tried again today after your replies, I got the
> same result. Here is my code:
> sub cancel : Local {
> 	my ($self,$c) = @_;
> 	my @options = $c->model('myleavedb::txn_mdl')->search({emp_no =>
> $c->user->emp_no},{columns => [qw/lv_id/]});
> 	$c->stash->{myoptions} = \@options;
> 	$c->stash->{template} = 'leavedata/cancel2_frm.tt2';
> 	}

Which is stashing an array of DBIC txn_mdl objects.
> Then I added a foreach loop as under and I got the expected results in
> the tt2 template. I also had to declare @new_options at the top.
> sub cancel : Local {
> 	my ($self,$c, at new_options) = @_;
> 	my @options = $c->model('myleavedb::txn_mdl')->search({emp_no =>
> $c->user->emp_no},{columns => [qw/lv_id/]});
> 	foreach my $option(@options) {
> 	push (@new_options,$option->lv_id)
> 	}
> 	$c->stash->{myoptions} = \@new_options;
> 	$c->stash->{template} = 'leavedata/cancel2_frm.tt2';
> 	}
> I don't understand in what way @options and @new_options are different
> from each other, but in a bumbling manner I have made the code work.
> What is the preferred way of writing this bit of code?

Erm, maybe if you showed us the DBIC classes?

Also, if you're going to reply to the list please subscribe normally rather
than to the digest - replying to the digest breaks threading for everybody
else because you aren't replying to an actual message.

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list