[Catalyst] Insert Multiple rows

Will Hawes info at whawes.co.uk
Mon Dec 19 17:54:37 CET 2005


Will Smith wrote:
> 
> Thank you,
> That's exactly what I am trying to do. I did the same thing, but could 
> not get the result. I guess because I used the wrong function
> Could I use this (obviously not, because I got error): for example, I 
> have 2 boxes named artistid
> sub do_insert : Local {
>     my ( $self, $c ) = @_;
>     my $artist = $c->req->param('artistid'); ##  if I use the params 
> (instead of param) I will get the value as column name instead
>     my $myvar;
>     for ($myvar=0;$myvar<2;$myvar++)
>     {
>     my $cd = mymusic::M::CDBI::Cd->find_or_create(artistid => $artist); 
> # the error is here , I get only 1 row created instead of 2 as desired. 
> When tried to use ->create only, it says need to get hash ....  so I 
> changed to : my %hash = (artistid => $c->req->param('artistid')); and 
> still get error
>     }

You should be fetching the 'artistid' parameter as an array and looping 
through the contents. Try something like this instead:

foreach my $artist ( @{$c->req->params->{artistid}} ) {
	my $cd = mymusic::M::CDBI::Cd->find_or_create(
		artistid => $artist
	);
}

BTW, please post error messages as they actually appear, rather than 
saying "it says ...". That makes it a lot easier for others to help.



More information about the Catalyst mailing list