[Twisted-Python] coding standard: plurals for database table names
Clark C. Evans
cce at clarkevans.com
Mon Apr 7 15:37:33 EDT 2003
On Sun, Apr 06, 2003 at 02:26:13PM -0400, Steve Waterbury wrote:
| On Sun, 2003-04-06 at 13:53, Clark C. Evans wrote:
| > I noticed in the Twisted Coding Standard that...
| >
| > "Database tables shall be named with plural nouns"
| >
| > I'd like to question this standard for several reasons:
| > [ some trimming for brevity ]
| >
| > 3. It is helpful to name foreign key columns as the
| > same name as the table that they are coming from.
|
| What if you have more than one foreign key to the same
| table? A very simple example (from my app ;^): the
| attributes "owner", "creator", and "modifier" all point
| to the "persons" table. As a rule of thumb, it's usually
| best to name the foreign key column after the role that
| the foreign key entity plays in the referring table.
If there is more than one role, I usually use 'role_table'
for my foreign keys. Otherwise it gets to be a bit messy,
especially if you use inheritance of sorts (there is not
only a person table but also an employee table, etc.) in
that case, 'creator' isn't good enough in some cases, you
may mean 'employee_creator' as not all person objects
may be possible of creating.
| > 5. While there are astechic reasons for this (above)
| > the resons become all the more important when
| > you want to build automatic tools for searching
|
| I didn't think it was all that difficult. I can send you
| the O-R mapping I use, if you like.
I'm not saying it isn't possible, it is just unnecessary
complexity, and to mandate this is quite irksome.
| > In short, I'd recommend singluar nouns, with M-M
| > link tables as one__two where one and two are
| > tables being linked to.
|
| One could reasonably argue that it is not important to have
| a table-naming rule in the coding standard.
That makes sense. I'd rather no standard is better than
a bad one. ;) Clark
More information about the Twisted-Python
mailing list