@@ -, +, @@ --- Koha/Patron/Attribute.pm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- a/Koha/Patron/Attribute.pm +++ a/Koha/Patron/Attribute.pm @@ -52,10 +52,10 @@ sub store { unless $type; Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self ) - unless $self->repeatable_ok($type); + unless $self->repeatable_ok; Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self ) - unless $self->unique_ok($type); + unless $self->unique_ok; return $self->SUPER::store(); } @@ -72,7 +72,9 @@ sub type { my $self = shift; - return scalar Koha::Patron::Attribute::Types->find( $self->code ); + $self->{_type} ||= Koha::Patron::Attribute::Types->find( $self->code ); + + return $self->{_type}; } =head3 authorised_value @@ -145,7 +147,11 @@ whether storing the current object state would break the repeatable constraint. sub repeatable_ok { - my ( $self, $type ) = @_; + my ( $self ) = @_; + + my $type = $self->type; + Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) + unless $type; my $ok = 1; if ( !$type->repeatable ) { @@ -172,7 +178,11 @@ whether storing the current object state would break the unique constraint. sub unique_ok { - my ( $self, $type ) = @_; + my ( $self ) = @_; + + my $type = $self->type; + Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) + unless $type; my $ok = 1; if ( $type->unique_id ) { --