[Dbix-class] DBIx::Class:Schema::Loader has_many relationshipnames

Adam Sjøgren asjo at koldfront.dk
Fri Feb 24 18:49:06 CET 2006


On Fri, 24 Feb 2006 17:18:08 -0000, Peter wrote:

>> Do most people really name their tables in the singular? I find that
>> quite confusing.

> It's very common practice for DBAs.
> The reasoning is that a single record represents a single item.

I understand. On the other hand, you could argue that the table holds
many items (one per row).

> Take for example a table holding car details.
> One record is one car, so you'd call the table "car".

Similarly, I could say that the table contains many cars, so I'd call
each row a car and the collection of all of them, the table, "cars"
;-)

We could probably go on about this, but as someone said earlier - it
basically is a matter of taste.

> It doesn't matter so much on a simple system but once you have many tables
> you will sooner or later end up with tables where one record represents a
> set of something and then a plural name is a helpful mnemonic, particularly
> when you start programming against it. 

This is a point I hadn't considered.

I would think it was a little fragile to have two tables with names
that only differed in the last 's', but still...

> my $car = DB::Car->find( name => 'Ford Focus' );
> (one car record)

(This reads funny in my head - find a car amongst one car?)

> my $car = DB::Cars->find( name => 'Ford Focus' );
> (is that one car or many? is $car a record or a recordset? should the
> variable be $cars?)

Even if I call the table cars, I would have the object that wraps a
single record be named MyApp::Car.

So my answer would be that the second 'my' should be 'my $cars=' and
hold a recordset - each record in that should be of a class called
MyApp::Car, representing one car.

(I (think I) understand that that kind of naming does not map really
well to the way the ORM works, but above I'm just stating what makes
sense "in my head", when I read it. My head will have to adapt).

> It seems silly, but I've wasted a lot of time supporting systems with a mix
> of pluralisation in table and variable names. When it's someone else's code
> you need to keep referring to the db defs to work out what's happening.

Yeah, the thing that is important is to have a consistent naming-rule
- so you don't have to think (good old laziness).

If I were the only one to touch a project, I'd probably go with the
rule that makes sense in my head (plural tablenames), but when there
are several people cooperating it makes more sense to go with the
default (so that as much stuff as possible works "out-of-the-box"), I
think.


  Best regards,

    Adam

-- 
 "I'd probably turn to something like mathematics. That       Adam Sjøgren
  would interest me. Architecture would interest me.     asjo at koldfront.dk
  Something like that."




More information about the Dbix-class mailing list