[Dbix-class] DBIx schema loader (dump schema using make_schema_at) wierd behaviour

Patrick Meidl patrick at pantheon.at
Wed Aug 8 07:03:02 GMT 2012


On Wed, Aug 08 2012, Rajeev Prasad <rp.neuli at yahoo.com> wrote:

> am I missing anything? when I dump schema of my database using schema
> loader's make_schema_at. Some .pm file names under Result
> corrosponding to folders have names chnaged! they do not match to
> table names!!   
>
> e.g. table name costlycookies shows up as Costlycooky.pm !!! another
> table cheapcookis show up as Cheapcooky.pm another table named els is
> showing up a El.pm !!!   

see here:

http://search.cpan.org/~rkitover/DBIx-Class-Schema-Loader-0.07025/lib/DBIx/Class/Schema/Loader/Base.pm#moniker_map

this states that the default behaviour of schema loader is to
singularise table names (so that your Result classes are singular). this
makes sense, since each of your objects represents a single entity.

you can override this behaviour, though:

http://search.cpan.org/~rkitover/DBIx-Class-Schema-Loader-0.07025/lib/DBIx/Class/Schema/Loader/Base.pm#inflect_singular

>  DBIx::Class::Schema::resultset(): Can't find source for Costlycookies
> at /my/path/cgi-bin/myscript.pl line 53  
>  
>  $coki_rs = $schema->resultset('Costlycookies')->search(....

since this singularisation is also performed for the ResultSet classes,
you have to call

    $coki_rs = $schema->resultset('Costlycooky')->search(....

to fetch cookies from the db.

whether it is best practice to use singular or plural table names is a
controversial question, see e.g. this thread:

http://stackoverflow.com/questions/338156/table-naming-dilemma-singular-vs-plural-names

I always use singular, since this is easiest to handle for ORMs (as your
question shows, plurals can cause confusion).

HTH

    patrick

-- 
Patrick Meidl ........................ patrick at pantheon.at
Vienna, Austria ...................... http://gplus.to/pmeidl




More information about the DBIx-Class mailing list