[Catalyst-commits] r13093 -
Catalyst-Authentication-Store-DBIx-Class/trunk/lib/Catalyst/Authentication/Store/DBIx/Class
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Mon Mar 29 00:35:26 GMT 2010
Author: rafl
Date: 2010-03-29 01:35:26 +0100 (Mon, 29 Mar 2010)
New Revision: 13093
Modified:
Catalyst-Authentication-Store-DBIx-Class/trunk/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm
Log:
Try supporting compound primary keys.
Modified: Catalyst-Authentication-Store-DBIx-Class/trunk/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm
===================================================================
--- Catalyst-Authentication-Store-DBIx-Class/trunk/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm 2010-03-29 00:25:46 UTC (rev 13092)
+++ Catalyst-Authentication-Store-DBIx-Class/trunk/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm 2010-03-29 00:35:26 UTC (rev 13093)
@@ -2,6 +2,7 @@
use strict;
use warnings;
+use List::MoreUtils qw(all);
use base qw/Catalyst::Authentication::User/;
use base qw/Class::Accessor::Fast/;
@@ -31,20 +32,15 @@
Catalyst::Exception->throw("\$c->model('${ \$self->config->{user_model} }') did not return a resultset. Did you set user_model correctly?");
}
- ## Note to self- add handling of multiple-column primary keys.
- if (!exists($self->config->{'id_field'})) {
- 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!");
- }
- }
+ $self->config->{'id_field'} = [$self->{'resultset'}->result_source->primary_columns]
+ unless exists $self->config->{'id_field'};
- 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!");
- }
+ $self->config->{'id_field'} = [$self->config->{'id_field'}]
+ unless ref $self->config->{'id_field'} eq 'ARRAY';
+ Catalyst::Exception->throw("id_field set to " . join(q{,} => @{ $self->config->{'id_field'} }) . " but user table has no column by that name!")
+ unless all { $self->{'resultset'}->result_source->has_column($_) } @{ $self->config->{'id_field'} };
+
## if we have lazyloading turned on - we should not query the DB unless something gets read.
## that's the idea anyway - still have to work out how to manage that - so for now we always force
## lazyload to off.
@@ -171,21 +167,21 @@
# return $self;
#
## if use_userdata_from_session is defined in the config, we fill in the user data from the session.
- if (exists($self->config->{'use_userdata_from_session'}) && $self->config->{'use_userdata_from_session'} != 0)
- {
+ if (exists($self->config->{'use_userdata_from_session'}) && $self->config->{'use_userdata_from_session'} != 0) {
my $obj = $self->resultset->new_result({ %$frozenuser });
$obj->in_storage(1);
$self->_user($obj);
return $self;
- } else {
- my $id;
- if (ref($frozenuser) eq 'HASH') {
- $id = $frozenuser->{$self->config->{'id_field'}};
- } else {
- $id = $frozenuser;
- }
- return $self->load( { $self->config->{'id_field'} => $id }, $c);
}
+
+ if (ref $frozenuser eq 'HASH') {
+ return $self->load({
+ map { ($_ => $frozenuser->{$_}) }
+ @{ $self->config->{id_field} }
+ });
+ }
+
+ return $self->load( { $self->config->{'id_field'} => $frozenuser }, $c);
}
sub get {
More information about the Catalyst-commits
mailing list