tmp

Top Diff List Search RSS Login
Page :: tmp
1
2
3
4
5
6
7
8
9
10
11
12
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;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#! /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');
をやるかどうかこれが肝。


1
2
3
4
5
6
7
8
9
10
11
12
13
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勉強す。

Last update time:2007/01/22 21:43:17