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

1

8

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?

Bigotry answered 16/3, 2014 at 14:49 Comment(0)
T
8

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;
Treadmill answered 16/3, 2014 at 17:27 Comment(1)
Thanks - I was doing this, though, and I was looking for amore straight, elegant way.Bigotry

© 2022 - 2024 — McMap. All rights reserved.