From: David Kamholz Date: Sat, 30 Jul 2005 17:23:49 +0000 (+0000) Subject: changed set_primary_key() to use Tie::IxHash so order of pk's is remembered. this... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6eec750187325f9ff6f97c7c9df654a36402b3e5;p=dbsrgits%2FDBIx-Class-Historic.git changed set_primary_key() to use Tie::IxHash so order of pk's is remembered. this permits e.g. retrieve() to be used without specifying column names --- diff --git a/Build.PL b/Build.PL index 1035d6c..3da7a5f 100644 --- a/Build.PL +++ b/Build.PL @@ -8,7 +8,8 @@ my %arguments = ( requires => { 'DBI' => 0, 'NEXT' => 0, - 'DBD::SQLite' => 1.08 + 'DBD::SQLite' => 1.08, + 'Tie::IxHash' => 0, }, create_makefile_pl => 'passthrough', create_readme => 1, diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index 32165dc..08d499f 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -2,6 +2,7 @@ package DBIx::Class::PK; use strict; use warnings; +use Tie::IxHash; use base qw/Class::Data::Inheritable DBIx::Class::SQL/; @@ -38,7 +39,8 @@ sub _ident_values { sub set_primary_key { my ($class, @cols) = @_; my %pri; - $pri{$_} = {} for @cols; + tie %pri, 'Tie::IxHash'; + %pri = map { $_ => {} } @cols; $class->_primaries(\%pri); } diff --git a/t/05multipk.t b/t/05multipk.t new file mode 100644 index 0000000..6aff06f --- /dev/null +++ b/t/05multipk.t @@ -0,0 +1,10 @@ +use Test::More; + +plan tests => 3; + +use lib qw(t/lib); + +use_ok('DBICTest'); + +ok(DBICTest::FourKeys->retrieve(1,2,3,4), "retrieve multiple pks without hash"); +ok(DBICTest::FourKeys->retrieve(5,4,3,6), "retrieve multiple pks without hash"); \ No newline at end of file diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 8203e60..a7ba0cb 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -31,6 +31,10 @@ CREATE TABLE tags (tagid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL, CREATE TABLE twokeys (artist INTEGER NOT NULL, cd INTEGER NOT NULL, PRIMARY KEY (artist, cd) ); +CREATE TABLE fourkeys (foo INTEGER NOT NULL, bar INTEGER NOT NULL, + hello INTEGER NOT NULL, goodbye INTEGER NOT NULL, + PRIMARY KEY (foo, bar, hello, goodbye) ); + CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY, artist INTEGER NOT NULL, cd INTEGER NOT NULL ); @@ -88,6 +92,10 @@ INSERT INTO twokeys (artist, cd) VALUES (1, 2); INSERT INTO twokeys (artist, cd) VALUES (2, 2); +INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (1, 2, 3, 4); + +INSERT INTO fourkeys (foo, bar, hello, goodbye) VALUES (5, 4, 3, 6); + INSERT INTO onekey (id, artist, cd) VALUES (1, 1, 1); INSERT INTO onekey (id, artist, cd) VALUES (2, 1, 2); @@ -158,12 +166,20 @@ DBICTest::TwoKeys->set_primary_key(qw/artist cd/); #DBICTest::TwoKeys->has_a(artist => 'SweetTest::Artist'); #DBICTest::TwoKeys->has_a(cd => 'SweetTest::CD'); +package DBICTest::FourKeys; + +use base 'DBICTest'; + +DBICTest::FourKeys->table('fourkeys'); +DBICTest::FourKeys->add_columns(qw/foo bar hello goodbye/); +DBICTest::FourKeys->set_primary_key(qw/foo bar hello goodbye/); + package DBICTest::OneKey; use base 'DBICTest'; DBICTest::OneKey->table('onekey'); DBICTest::OneKey->add_columns(qw/id artist cd/); -DBICTest::TwoKeys->set_primary_key('id'); +DBICTest::OneKey->set_primary_key('id'); 1;