[英]Why does DBIx::Class::Schema::Loader change my table name from plural to singular?
I'm using DBIx::Class::Schema::Loader to create a schema like this: 我正在使用DBIx :: Class :: Schema :: Loader创建这样的模式:
#!/usr/bin/perl
use strict;
use warnings;
use DBIx::Class::Schema::Loader qw/make_schema_at/;
make_schema_at(
"Mydb::Schema",
{debug => 0, dump_directory => "../db/",
generate_pod => 0,},
["dbi:mysql:mydb:localhost:3306", 'mydb', 'password'],
);
My table name in MySQL is people
, but when I run this code, the generated class is named Mydb::Schema::Result::Person
: 我在MySQL中的表名是
people
,但是当我运行此代码时,生成的类名为Mydb::Schema::Result::Person
:
$ cat Mydb/Schema/Result/Person.pm
use utf8;
package Mydb::Schema::Result::Person;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("people");
__PACKAGE__->add_columns(
"pplid",
{
data_type => "smallint",
extra => { unsigned => 1 },
is_auto_increment => 1,
is_nullable => 0,
},
...
...
Why is "people" being converted to "Person"? 为什么将“人”转换为“人”?
By default, DBIx::Class::Schema::Loader singularizes the names of Result classes. 默认情况下,DBIx :: Class :: Schema :: Loader将Result类的名称单数化。 It makes sense to have a database table of people, but it doesn't make sense to have an object representing a single person called "People".
拥有一个人的数据库表是有意义的,但是拥有一个代表一个人的对象称为“人”是没有意义的。
If you really want, you can change this by setting the naming
option in make_schema_at
: 如果确实需要,可以通过在
make_schema_at
设置naming
选项来更改此设置:
make_schema_at(
"Mydb::Schema",
{
debug => 0,
dump_directory => "../db/",
generate_pod => 0,
naming => { monikers => 'preserve' }
},
["dbi:mysql:mydb:localhost:3306", 'mydb', 'password'],
);
But I would recommend sticking with the defaults. 但我建议您坚持使用默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.