Revision #2 has been created by Maurizio Domba Cerin on Aug 27, 2011, 8:26:53 PM with the memo:
doc fix
« previous (#1) next (#3) »
Changes
Title
unchanged
Guidelines for good schema design
Category
unchanged
Tips
Yii version
unchanged
Tags
unchanged
database, schema design
Content
changed
[...]
But even without Yii considering them, foreign-keys are a vital part of maintaining referential integrity of your database; there are many tutorials on the web on how to learn about them.
DO name your foreign key fields ending in "id"
----------------------------------------------
Related to the prior note, if a you have a field that holds the ID of a user, call the field `userid` rather than `user`. This is because for every foreign key you include in a table, you'll almost certainly wish to define a **relation** for it.
In Yii, class variables, db fields, virtual attributes, relations all share a single namespace, so it's not possible to have `$model->user` be **both** the foreign key in the table **and** the relation.
By calling the FK `userid`, the BELONGS_TO relation of `$model->user` forms naturally and easily:[...]