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>
}
}
+=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.
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;
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;