Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Vanilla 2.6 is here! It includes security fixes and requires PHP 7.0. We have therefore ALSO released Vanilla 2.5.2 with security patches if you are still on PHP 5.6 to give you additional time to upgrade.

How to create tables with foreign keys correctly?

edited November 2015 in Development

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

Comments

Sign In or Register to comment.