1. Establishing standards for field types
2. Table and field name standardisation
There are, of course, some other things like moving to InnoDB, etc, so
just bring them up at appropriate times.
Begin :)
Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer
> On the foreign key, I prefer NULL. Any value implies a relationship. But if
> zero is allowed, it should consistently be used as default for all foreign
> keys. NULL is technically correct.
I'd prefer NULL, too. Disk space is not a problem nowadays. In some
cases I've been using 0 as a valid id. A user record with ID=0 for
example could contain general settings for guests.
> Pivot tables are (hopefully) 1:M and the name might better reflect that
> relationship as singular, then plural. user_sessions better describes the
> subject of the table: the *sessions* (that belong to a specific user.)
The multiplicity of a relation should be reflected by the table name:
1:1 - singular1_singular2_map
1:n - singular1_plural2_map
n:m - plural1_plural2_map
The suffix '_map' (or '_xref') makes it easier to distinguish maps from
3PD component related tables.
Additionally, there should be a convention for component specific prefixes.
> I could go either way with the primary key question. From a strict data
> modeling perspective, no two distinct data elements should have the same
> name. I also agree with Sam that joins using aliases can get confusing (and
> potentially introduce bugs). On the other hand, it sure is quick to type *id
> * and it does make it clear which table contains the primary key and which
> contains the foreign key.
I don't understand, why
SELECT ... FROM product
... JOIN attribute ON attribute.product_id=product.product_id
is considered to be less confusing than
SELECT ... FROM product
... JOIN attribute ON attribute.product_id=product.id
As you say, Amy, the latter one has the benefit to show, that product is
the master, while attribute contains details. This intuitivity is
somehow lost in the first example.
Regards,
Niels
You can get JForm to handle it with an attribute in the XML
definition. But, really, I know it *is* technically correct from a
data model standpoint, but in reality does accounting for null
actually add any value over using zero in that majority of cases? If
you want to handle default values, use a real, reserved number (like
1). In PHP land you then miss out on simple checks like empty() as
opposed to doing a triple check on null, then zero, then a positive
value. Another way of putting it is Joomla currently works happily on
NOT NULL FK's - what is the value to me, the developer, that I can
pass on to the user by using null FK's?
If it makes sense, let's do it, but I'm erring on the side that I'm
not convinced it's worth the trouble.
BTW, this is the advice I was given during MySQL training by one of
the guys that wrote MySQL. Admittedly that was only his opinion, but
hey :)
On cross-reference tables I could certainly go with:
1 to N: jos_user_sessions
M to N: jos_users_usergroups
That makes sense to me.
Another thing to add is a 3PD should have an extra namespace to avoid
collisions with other extensions.
David, do you want to start a wiki page to collect the thoughts as we go?