I am developing a custom component and want to use a foreign key user_id
referenced to #__users(id)
. I noticed that Joomla doesn't use any foreign key in its core tables for example in #__user_notes
or user_profiles
.
Assume that I want to create an extension for adding comments to articles. The structure of the table is like so:
CREATE TABLE IF NOT EXISTS `#__comp_comments` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(20) unsigned NOT NULL,
`comment` text,
PRIMARY KEY (`id`)
/* PLACEHOLDER */
);
Now I have two options:
, FOREIGN KEY (`user_id`) REFERENCES `#__users`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
and
, KEY `idx_userid` (`user_id`)
What is your suggestion? Using foreign keys in custom components or not? And why?
#__users
, all articles belongs to the user, will be deleted too.