[Dbix-class] Dose DBIx::Class necessary need primary key?

atsushi kobayashi kak-829 at nifty.com
Mon Feb 6 13:24:56 CET 2006


Hi all.

I tried DBIx::Class-0.05000 & DBIx::Class-0.05001 with SQLite3 & MySQL.
This script doesn't work on My PC.

package DBIC;

use strict;
use warnings;
use base 'DBIx::Class::Schema';

__PACKAGE__->load_classes(qw/Test/);

1;

package DBIC::Test;

use strict;
use warnings;
use base 'DBIx::Class';

__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('test');
__PACKAGE__->add_columns(qw/id name/);

#__PACKAGE__->set_primary_key('id'); # This id colum is not primary key!

1;

#! /usr/bin/perl

use strict;
use warnings;
use DBIC;
my $schema = DBIC->connect('dbi:SQLite:test.db');

my $t = $schema->resultset('Test');

my $it = $t->search({id => [1,2,3],name => 'test'});
my $i=1;
for ($it->all) {
$_->name("test $i");
$_->update;
$i++;
}

before data:

sqlite> select * from test;
1|test
1|sub test
2|test
2|sub test
3|test
3|sub test
sqlite>


This script shows following error:

DBIx::Class::Relationship::CascadeActions::update(): Can't update
DBIC::Test=HASH(0xa254c8c): updated more than one row at ./test.pl line 18

And all colume updated.

after data:

sqlite> select * from test;
1|test 1
1|test 1
2|test 1
2|test 1
3|test 1
3|test 1
sqlite>

test.db's SQL is here:

CREATE TABLE test (
id INTEGER NOT NULL,
name varchar(40)
);

id colum is not Primary key.
Dose DBIx::Class necessary need primary key?

MySQL was same.
Any ideas ?





More information about the Dbix-class mailing list