@@ -, +, @@ --- Koha/Objects.pm | 13 +++++++++++++ t/db_dependent/Koha/Objects.t | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) --- a/Koha/Objects.pm +++ a/Koha/Objects.pm @@ -234,6 +234,19 @@ sub _wrap { return @objects; } +=head3 update + + Koha::Objects->search({ $key => $value})->update( \%values ); + +Sets the specified columns in the resultset to the supplied values in a single query. + +=cut + +sub update { + my ( $self, $params ) = @_; + return $self->_resultset()->update($params); +} + =head3 Koha::Objects->_resultset Returns the internal resultset or creates it if undefined --- a/t/db_dependent/Koha/Objects.t +++ a/t/db_dependent/Koha/Objects.t @@ -19,9 +19,10 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Koha::Authority::Types; +use Koha::Cities; use Koha::Patrons; use Koha::Database; @@ -36,5 +37,19 @@ my @columns = Koha::Patrons->columns; my $borrowernumber_exists = grep { /^borrowernumber$/ } @columns; is( $borrowernumber_exists, 1, 'Koha::Objects->columns should return the table columns' ); +subtest 'update' => sub { + plan tests => 2; + my $builder = t::lib::TestBuilder->new; + $builder->build( { source => 'City', value => { city_country => 'UK' } } ); + $builder->build( { source => 'City', value => { city_country => 'UK' } } ); + $builder->build( { source => 'City', value => { city_country => 'UK' } } ); + $builder->build( { source => 'City', value => { city_country => 'France' } } ); + $builder->build( { source => 'City', value => { city_country => 'France' } } ); + $builder->build( { source => 'City', value => { city_country => 'Germany' } } ); + Koha::Cities->search( { city_country => 'UK' } )->update( { city_country => 'EU' } ); + is( Koha::Cities->search( { city_country => 'EU' } )->count, 3, 'Koha::Objects->update should have updated the 3 rows' ); + is( Koha::Cities->search( { city_country => 'UK' } )->count, 0, 'Koha::Objects->update should have updated the 3 rows' ); +}; + $schema->storage->txn_rollback; 1; --