[Dbix-class] Strangely does DBIx change table names from MySQL?

Jorge Gonzalez jorge.gonzalez at daikon.es
Fri Mar 10 17:12:35 GMT 2017


DBIC by default follows the convention that table names reflect the entity name in singular. If It detects table names in plural It uses a Lingua::* module to deduce the apropriate singular name, and names the clases with It.

In your case, the table names IS "people", but the generated class name IS "Person", the singular for people.

Admittedly yours IS a bit of an extreme case :-)

This behaviour can be changed, see the docs for DBIC::Schema::Loader and search for an option named like "*inflect*" or something similar (I'm on my cellphone and can't search at the moment :-)

BR
J.

-- 
Jorge González Villalonga
Ingeniero de Sistemas / Systems Engineer
Red Hat Certified Engineer #140-183-666
Móvil / Cell: (+34) 672 173 200

-----Original Message-----
From: Rajeev Prasad <rp.neuli at yahoo.com>
To: "DBIx::Class User and Developer List" <dbix-class at lists.scsys.co.uk>, "dbi-users at perl.org" <dbi-users at perl.org>, Mysql Mailing List <mysql at lists.mysql.com>, "mysql-index at lists.mysql.com" <mysql-index at lists.mysql.com>
Sent: vie., 10 mar. 2017 17:49
Subject: [Dbix-class] Strangely does DBIx change table names from MySQL?

Hello,
Note: this question is also posted on Stack Overflow, a few minutes back.
  
| 
 | While using ./create-schema-mydb.pl I realized that the table name "People" is changed to "Person" in DBIx. I am not sure how? or why?
It is not even a reserved word.

in MySQL:people innoDB utf8

create-schema script:$ cat ./create-schema-mydb.pl
#!/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'],
);


It shows up like this after create-schema... note the change in name from People to Person, but inside the .pm file table name is retained as People !!!
Result$ cat 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,
  },
...
...

only relevant portion shown above...


Thank you.

Rajeev
  |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20170310/0bcb3530/attachment-0001.htm>


More information about the DBIx-Class mailing list