문제

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?

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top