Welcome Guest, Not a member yet? Register   Sign In
name rule for the tables primary id, plural or not?
#1

[eluser]searain[/eluser]
For example, in the zen cart.

The table definition for products is

http://www.zen-cart.com/wiki/index.php/Table_products

Table: products
Primary Key: products_id

Note:

The key is "products_id" Not "product_id"

Now

Here is Jay Tee's example for

http://ellislab.com/forums/viewthread/57514/#282983

Table: invoices
Primary Key: invoice_id

Note:

The key is "invoice_id" not "invoices_id"

Question:

So looks like when we name tables we use plural format. But when we name the primary id of that table, some times we use plural format, some times we don't. What is the best practice here?

I know it is a small issue and either way should be OK. I used to use plural format for the primary key (id) etc. like Zen Cart did. Once I did it years ago, I keep using the plural format for the primary key(id) to be consistent.

But now I am starting to write some projects on CI, I think if I should change my old habit, I should do it now.

Any advices?

Thanks!
#2

[eluser]Thorpe Obazee[/eluser]
Read through this post : http://ellislab.com/forums/viewthread/114249/
#3

[eluser]jedd[/eluser]
Verily, this is a subject that engenders much discussion and little in the way of consensus.

For my part, the same reasons that prevent pretty much everyone from calling their primary key column ids are the same reasons that I cite when sticking with singular pretty much everywhere.

Of course, some people just can't see the logic of this argument ... Wink

From a more pragmatic POV, consistency is almost definitely the key (ha ha) here, and so it would be especially frustrating to work with a library that was at odds with your own adopted standard. I'd suggest the pain of modifying the relevant bits to align with your application would be worth it.
#4

[eluser]searain[/eluser]
Thanks!

You guys are really helpful and responses are really quick in this forum.

OK, now we settled the primary id issue.

How about "precede the field name with the table name"? I read the posts from the above thread, and there were debates at this issue but it seemed no major decision yet.

I am not trying to start another debate here. Just want to get a quick responses that what you do? precede the field name with the table name or not?

Due to I followed the Zen Cart name rule before, I preceded the field name with the table name before. Wondering should I change it or not?
#5

[eluser]jedd[/eluser]
I'm sure it's an especially useful thing to do if you're working on a keyboard where the . key doesn't work.

Other than that, I remain doubleplusunconvinced.
#6

[eluser]Thorpe Obazee[/eluser]
[quote author="blackhorse66" date="1244526774"]Thanks!

How about "precede the field name with the table name"? I read the posts from the above thread, and there were debates at this issue but it seemed no major decision yet.

I am not trying to start another debate here. Just want to get a quick responses that what you do? precede the field name with the table name or not?[/quote]

I don't see any reason for putting the table name in field names. If there will be any collisions then that where aliases come in. (So that's what I do)




Theme © iAndrew 2016 - Forum software by © MyBB