How to create tables with foreign keys correctly?
Hello again!
As I said before, I'm creating an application (to create "Jams"), i'm trying to understand now the database structure file (creation scripts).
By now I have this for foreign keys:
$Construct->Table('GroupUser'); $Construct ->PrimaryKey('GroupUserID') ->Column('UserID', 'int', FALSE, 'key') ->Column('GroupID', 'int', FALSE, 'key') ->Column('DateCreated', 'datetime', NULL) ->Column('DateUpdated', 'datetime', NULL) ->Column('IsPublic', 'tinyint(1)', '1') ->Set($Explicit, $Drop);
But I use also this when a FK is a PK member in another table:->Column('GroupID', 'int', FALSE, array('primary', 'key'))
Although, in other applications I see they don't use "key" for FK's in some cases.
How's the better way to do it?
Thank you!
Off-topic: I ask under this category because I can't select "development", and I just upgraded to v2.2
Best Answer
-
Bleistivt Moderator
Vanilla doesn't make use of foreign key contraints in the database, so adding
key
orindex
is for optimization only.My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
1
Answers
@blzkz
I think @Linc or @Adrian can give you access to the Development category if you want it.
@whu606 done.
Thank you @whu606 and @Linc
Vanilla doesn't make use of foreign key contraints in the database, so adding
key
orindex
is for optimization only.My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS