Now throws exceptions when id_field is invalid or can not be determined
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / lib / Catalyst / Plugin / Authentication / Store / DBIx / Class / User.pm
index b5d3958..1693a8c 100644 (file)
@@ -23,7 +23,15 @@ sub new {
     
 
     if (!exists($self->config->{'id_field'})) {
-        $self->config->{'id_field'} = 'id';
+        my @pks = $self->{'resultset'}->result_source->primary_columns;
+        if ($#pks == 0) {
+            $self->config->{'id_field'} = $pks[0];
+        } else {
+            Catalyst::Exception->throw("user table does not contain a single primary key column - please specify 'id_field' in config!");
+        }
+    }
+    if (!$self->{'resultset'}->result_source->has_column($self->config->{'id_field'})) {
+        Catalyst::Exception->throw("id_field set to " .  $self->config->{'id_field'} . " but user table has no column by that name!");
     }
     
     ## if we have lazyloading turned on - we should not query the DB unless something gets read.
@@ -104,7 +112,10 @@ sub roles {
     
     my @roles = ();
     if (exists($self->config->{'role_column'})) {
-        @roles = split /[ ,\|]+/, $self->get($self->config->{'role_column'});
+        my $role_data = $self->get($self->config->{'role_column'});
+        if ($role_data) { 
+            @roles = split /[ ,\|]+/, $self->get($self->config->{'role_column'});
+        }
         $self->_roles(\@roles);
     } elsif (exists($self->config->{'role_relation'})) {
         my $relation = $self->config->{'role_relation'};
@@ -176,7 +187,7 @@ module.
 
 =head1 VERSION
 
-This documentation refers to version 0.02.
+This documentation refers to version 0.10.
 
 =head1 SYNOPSIS