tmp's Change point

Top List Search RSS Login
+{{code Perl,4,
+package Neko::Schema::User;
+
+use strict;
+use warnings;
+use base 'DBIx::Class';
+
+__PACKAGE__->load_components(qw/PK::Auto::SQLite Core/);
+__PACKAGE__->table('user');
+__PACKAGE__->add_columns(qw/id name/);
+#__PACKAGE__->set_primary_key('id');
+
+1;
+}}
+
+{{code Perl,4,
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use Neko::Schema;
+use Data::Dumper;
+my $schema = Neko::Schema->connect('dbi:SQLite:/home/nekokak/dbix/nekodb.db');
+
+my $n = $schema->resultset('User');
+
+my $it = $n->search({id => [1,2]});
+my $i=4;
+for ($it->all) {
+    $_->name("koba$i");
+    $_->update;
+    $i++;
+}
+}}
+
+my $it = $n->search();
+で検索かけて、1レコードずつupdateだと問題なし。
+my $it = $n->search({id => [1,2]});
+で絞り込んだ検索で1レコードずつupdateかけると問題あり。
+
+#__PACKAGE__->set_primary_key('id');
+をやるかどうかこれが肝。
+
+----
+
+
+{{code Perl,4,
+my $n = $schema->resultset('User');
+
+my $it = $n->search({id => [1,2]});
+#while ( my $user = $it->next ) {
+my $i = 3;
+foreach my $user ( $it->all ) {
+    print $user->id,':',$user->name,"\n";
+    $user->name("hogeneko$i");
+print "2\n";
+    $user->update;
+print "3\n";
+    $i++;
+}
+}}
+
+$ ./test.pl
+1:hogeneko4
+2
+DBIx::Class::Relationship::CascadeActions::update(): Can't update Neko::Schema::User=HASH(0x87d8aa0): updated more than one row at ./test.pl line 19
+
+
+----
+
+CPANPLUS勉強す。