Subject: | is_auto_increment being removed from source tables |
The is_auto_increment attributes are being removed from the primary key columns in the left
and right tables, as a side-effect of removing them in order to create the map table.
I've attached a patch (including tests) which will remove the is_auto_increment for the mapping
table while leaving the left and right tables unaffected.
(Tested with DBIC 0.08010 and 0.08099_05)
Subject: | DBICx-MapMaker.patch |
diff --git a/lib/DBICx/MapMaker.pm b/lib/DBICx/MapMaker.pm
index 3ba64d7..78e96bc 100644
--- a/lib/DBICx/MapMaker.pm
+++ b/lib/DBICx/MapMaker.pm
@@ -86,13 +86,10 @@ sub setup_table {
# NOTE:
# we never want auto-incrementing
- # in a maping table, so remove it
- # - SL
- delete $_->{is_auto_increment} for ($l_info, $r_info);
-
+ # in a mapping table, so explicitly disable it
$class->add_columns(
- $left_name => { %$l_info, is_nullable => 0, },
- $right_name => { %$r_info, is_nullable => 0, },
+ $left_name => { %$l_info, is_auto_increment => 0, is_nullable => 0, },
+ $right_name => { %$r_info, is_auto_increment => 0, is_nullable => 0, },
);
$class->set_primary_key($left_name, $right_name);
diff --git a/t/synopsis.t b/t/synopsis.t
index 4f80777..e1218c8 100644
--- a/t/synopsis.t
+++ b/t/synopsis.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 12;
+use Test::More tests => 16;
use DBICx::TestDatabase;
use ok 'DBICx::MapMaker';
@@ -9,7 +9,7 @@ use ok 'DBICx::MapMaker';
__PACKAGE__->load_components('Core');
__PACKAGE__->table('a');
__PACKAGE__->add_columns(
- id => { data_type => 'INTEGER' },
+ id => { data_type => 'INTEGER', is_auto_increment => 1 },
foo => { data_type => 'TEXT' },
);
__PACKAGE__->set_primary_key('id');
@@ -19,7 +19,7 @@ use ok 'DBICx::MapMaker';
__PACKAGE__->load_components('Core');
__PACKAGE__->table('b');
__PACKAGE__->add_columns(
- id => { data_type => 'INTEGER' },
+ id => { data_type => 'INTEGER', is_auto_increment => 1 },
foo => { data_type => 'TEXT' },
);
__PACKAGE__->set_primary_key('id');
@@ -60,6 +60,7 @@ ok $a->b_map;
ok $a->bs;
is $a->b_map->count, '1';
is [$a->bs]->[0]->foo, 'b1';
+is $a->column_info('id')->{'is_auto_increment'}, 1;
my $b = $schema->resultset('B')->find(1);
ok $b;
@@ -67,3 +68,8 @@ ok $b->a_map;
ok $b->as;
is $b->a_map->count, '1';
is [$b->as]->[0]->foo, 'a1';
+is $b->column_info('id')->{'is_auto_increment'}, 1;
+
+my $map = $schema->resultset('MapAB')->find({ a => 1, b => 1 });
+isnt $map->column_info('a')->{'is_auto_increment'}, 1;
+isnt $map->column_info('b')->{'is_auto_increment'}, 1;