[Catalyst] Create multiple records

Will Smith willbelair at yahoo.com
Fri Dec 29 20:27:19 GMT 2006


Thank you,
 Yes, I mean I'm using DBIC. I've tried your method. It did not give error, but, also did not insert into the table.
 Do I miss something?
 

Jonathan Rockway <jon at jrock.us> wrote: Will Smith wrote:
> Hi,
> Could someone please show me the syntax to create multiple records. For
> example my table book has 3 fields : id (auto_increment), title, price.
> On the template I have 3 rows of title/price. I want to enter 3 book
> titles and prices and create at the same time.
> With the old syntax, I can do something like
> my $book = myapp::M::CDBI::Book::Shift->create(\%hash);

Are you really using CDBI?  If so, switch to DBIC and do:


   push @records, {title => "foo", price => "13.37"};
   # same thing a few more times...
   eval {
      $c->model('BookDB::Books')->create($_) for (@records);
   }
   die "Error: $@" if($@);

or something similar.

-- 
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;

_______________________________________________
List: Catalyst at lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/


 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061229/537fcae1/attachment.htm


More information about the Catalyst mailing list