Bug 16889: Add Koha::Objects->columns
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 9 Jul 2016 13:32:40 +0000 (14:32 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 15 Jul 2016 18:12:12 +0000 (18:12 +0000)
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.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/Objects.pm
t/db_dependent/Koha/Objects.t

index 6c03ff5..c365e7f 100644 (file)
@@ -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.
index 830db76..b92239a 100644 (file)
 
 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;