[Dbix-class] DBIx::Class:Schema::Loader has_many relationship names

Matt S Trout dbix-class at trout.me.uk
Fri Feb 24 13:42:02 CET 2006


On Fri, Feb 24, 2006 at 11:12:33AM +0100, Adam Sjøgren wrote:
>   Hi.
> 
> 
> I have a question about DBIx::Class::Schema::Loader's (0.02003)
> automatic has_many-releationship creation; more specifically the
> naming of the relationsships.
> 
> It is probably easiest to illustrate with a tiny example. When I
> create a database like this:
> 
> CREATE TABLE cars (
>   id serial NOT NULL,
>   PRIMARY KEY (id)
> );
> 
> CREATE TABLE passengers (
>   id serial NOT NULL,
>   car integer REFERENCES cars NOT NULL,
>   PRIMARY KEY (id)
> );
> 
> ... what I expect to get is a Passengers->belongs_to(car) and a
> Cars->has_many(passengers)-relationship.
> 
> But the has_many is called "passenger", singular, by
> DBIx::Class::Schema::Loader.

That's because the default inflect code doesn't handle plurals - if you
want non-default behaviour, pass it an inflect_map option.

I can see your reasoning but the vast majority of users (I think) have
singular table names rather than plural, so the default config caters to
that.

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list