# Handle not null and default values for integers and dates
foreach my $col ( keys %{$columns_info} ) {
# Integers
- if ( _numeric_column_type( $columns_info->{$col}->{data_type} ) ) {
+ if ( _numeric_column_type( $columns_info->{$col}->{data_type} )
+ or _decimal_column_type( $columns_info->{$col}->{data_type} )
+ ) {
# Has been passed but not a number, usually an empty string
my $value = $self->_result()->get_column($col);
if ( defined $value and not looks_like_number( $value ) ) {
catch {
# Catch problems and raise relevant exceptions
if (ref($_) eq 'DBIx::Class::Exception') {
+ warn $_->{msg};
if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) {
# FK constraints
# FIXME: MySQL error, if we support more DB engines we should implement this for each
sub update {
my ($self, $values) = @_;
- return $self->set($values)->store();
+ Koha::Exceptions::Object::NotInStorage->throw unless $self->in_storage;
+ $self->set($values)->store();
}
=head3 $object->delete();
) {
# TODO: Remove once the solution for
- # https://rt.cpan.org/Ticket/Display.html?id=119904
+ # https://github.com/perl5-dbi/DBD-mysql/issues/212
# is ported to whatever distro we support by that time
+ # or we move to DBD::MariaDB
$unblessed->{$col} += 0;
}
+ elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} )
+ and looks_like_number( $unblessed->{$col} )
+ ) {
+
+ # TODO: Remove once the solution for
+ # https://github.com/perl5-dbi/DBD-mysql/issues/212
+ # is ported to whatever distro we support by that time
+ # or we move to DBD::MariaDB
+ $unblessed->{$col} += 0.00;
+ }
elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) {
eval {
return unless $unblessed->{$col};
sub _numeric_column_type {
# TODO: Remove once the solution for
- # https://rt.cpan.org/Ticket/Display.html?id=119904
+ # https://github.com/perl5-dbi/DBD-mysql/issues/212
# is ported to whatever distro we support by that time
+ # or we move to DBD::MariaDB
my ($column_type) = @_;
my @numeric_types = (
'mediumint',
'smallint',
'tinyint',
+ );
+
+ return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0;
+}
+
+sub _decimal_column_type {
+ # TODO: Remove once the solution for
+ # https://github.com/perl5-dbi/DBD-mysql/issues/212
+ # is ported to whatever distro we support by that time
+ # or we move to DBD::MariaDB
+ my ($column_type) = @_;
+
+ my @decimal_types = (
'decimal',
'double precision',
'float'
);
- return ( grep { $column_type eq $_ } @numeric_types) ? 1 : 0;
+ return ( grep { $column_type eq $_ } @decimal_types) ? 1 : 0;
}
=head3 prefetch_whitelist
my $result_class = $relations->{$key}->{class};
my $obj = $result_class->new;
try {
- $whitelist->{$key} = $obj->koha_object_class;
+ $whitelist->{$key} = Koha::Object::_get_object_class( $obj->result_class );
} catch {
$whitelist->{$key} = undef;
}