From 365e2e54914b2a010f3611aea98c88edf9fef277 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 9 Jul 2016 14:32:40 +0100 Subject: [PATCH] Bug 16889: Add Koha::Objects->columns Currently we have 3 subroutines to retrieve the columns of tables: C4::Members::columns, C4::Items::columns and C4::Items::biblioitems_columns. It is easier to have a Koha::Objects->columns method to provide the different classes to retrieve their related column names. --- Koha/Objects.pm | 15 +++++++++++++++ t/db_dependent/Koha/Objects.t | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 6c03ff5..c365e7f 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -254,6 +254,21 @@ sub _resultset { } } +=head3 columns + +my @columns = Koha::Objects->columns + +Return the table columns + +=cut + +sub columns { + my ( $class ) = @_; + return Koha::Database->new->schema->resultset( $class->_type )->result_source->columns; +} + + + =head3 _type The _type method must be set for all child classes. diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index 830db76..b92239a 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -19,9 +19,10 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Koha::Authority::Types; +use Koha::Patrons; use Koha::Database; use t::lib::TestBuilder; @@ -31,5 +32,9 @@ $schema->storage->txn_begin; is( ref(Koha::Authority::Types->find('')), 'Koha::Authority::Type', 'Koha::Objects->find should work if the primary key is an empty string' ); +my @columns = Koha::Patrons->columns; +my $borrowernumber_exists = grep { /^borrowernumber$/ } @columns; +is( $borrowernumber_exists, 1, 'Koha::Objects->columns should return the table columns' ); + $schema->storage->txn_rollback; 1; -- 2.8.1