Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the class name for a table in DBIx::Class

Finding the table name for a class in DBIx::Class is straightforward, like this

my $s = DBIx::Class::Schema::Loader->connect('dbi:SQLite:foo.db');
$s->class($class_name)->table;

but how can I do the opposite, and get the class name from the name of the table in the database?

like image 911
simone Avatar asked Mar 16 '14 14:03

simone


1 Answers

Use $schema->sources to get a list of all source names in a schema. Then you can grep for the one matching your table:

my ($class_name) = grep { $s->class($_)->table eq $table } $s->sources;
like image 190
nwellnhof Avatar answered Nov 15 '22 16:11

nwellnhof