From: Matt S Trout Date: Thu, 1 Dec 2005 17:49:11 +0000 (+0000) Subject: Patch from abraxxa to make set_primary_key barf if called with non-existant columns X-Git-Tag: v0.05005~160 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6a94f7f49486ca5ad76cfaf1e380bbb787da7e0e;p=dbsrgits%2FDBIx-Class.git Patch from abraxxa to make set_primary_key barf if called with non-existant columns --- diff --git a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm index d87e6a4..80b17e0 100644 --- a/lib/DBIx/Class/CDBICompat/ColumnGroups.pm +++ b/lib/DBIx/Class/CDBICompat/ColumnGroups.pm @@ -19,8 +19,8 @@ sub columns { sub _add_column_group { my ($class, $group, @cols) = @_; - $class->_register_column_group($group => @cols); $class->add_columns(@cols); + $class->_register_column_group($group => @cols); } sub _register_column_group { diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index ddd37b9..b532a33 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -43,6 +43,11 @@ define one or more columns as primary key for this class sub set_primary_key { my ($class, @cols) = @_; + # check if primary key columns are valid columns + for (@cols) { + $class->throw( "Column $_ can't be used as primary key because it isn't defined in $class" ) + unless $class->has_column($_); + } my %pri; tie %pri, 'Tie::IxHash', map { $_ => {} } @cols; $class->_primaries(\%pri);