Versionable Behavior & Inheritance
Bonjour à tous,
Voilà, j'étais entrain de faire quelques tests pour un prochain projet, et en établissant le modèle, je suis tombé sur une petite singularité qui m'échappe franchement...
Un petit bout de schema :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
Help:
inheritance:
extends: ExtraContent
type: column_aggregation
keyField: type
keyValue: "help"
Background:
inheritance:
extends: ExtraContent
type: column_aggregation
keyField: type
keyValue: "background"
ExtraContent:
tableName: exco_content
actAs:
Versionable:
actAs:
Timestampable:
updated:
disabled: true
Signable:
created:
name: created_by
type: string
onUpdate: CASCADE
onDelete: SET NULL
options:
notnull: true
default: 'application'
updated:
disabled: true
columns:
id:
type: integer(4)
primary: true
autoincrement: true
code:
type: string(25)
notnull: true
unique: true
title:
type: string(255)
notnull: true
message:
type: clob
notnull: true |
L'idée est très simple (enfin, tout du moins pas trop compliqué) je veux me servir de l'héritage pour mutualiser un comportement dicté par quelques behaviors. Donc j'ai ma Super-Entité ExtraContent qui porte cette logique, et deux autres entités en héritent (et pour l'instant, se contentent d'en hériter) : Help & Background.
Le schema se construit, pas de problème. En revanche, quand je vois ce qui a été généré, j'ai un doute sur ma conception (rapide, je l'avoue) :
La table de la super-entité :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
CREATE TABLE IF NOT EXISTS `exco_content` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(25) NOT NULL,
`template_id` int(11) DEFAULT NULL,
`title` varchar(255) NOT NULL,
`message` longtext NOT NULL,
`type` varchar(255) DEFAULT NULL,
`version` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`),
KEY `exco_content_type_idx` (`type`),
KEY `template_id_idx` (`template_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
La table des versions de la super-entité (déjà ici, j'aime pas le nommage, mais passons) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
CREATE TABLE IF NOT EXISTS `extra_content_version` (
`id` int(11) NOT NULL DEFAULT '0',
`code` varchar(25) NOT NULL,
`template_id` int(11) DEFAULT NULL,
`title` varchar(255) NOT NULL,
`message` longtext NOT NULL,
`type` varchar(255) DEFAULT NULL,
`version` bigint(20) NOT NULL DEFAULT '0',
`created_at` datetime NOT NULL,
`created_by` varchar(255) NOT NULL DEFAULT 'application',
PRIMARY KEY (`id`,`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `extra_content_version`
ADD CONSTRAINT `extra_content_version_id_exco_content_id` FOREIGN KEY (`id`) REFERENCES `exco_content` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; |
Pour moi, ça aurait dû s'arrêter là. Mais il m'a généré deux autres tables.
Les table des versions des entités filles Help & Background
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
CREATE TABLE IF NOT EXISTS `background_version` (
`id` int(11) NOT NULL DEFAULT '0',
`code` varchar(25) NOT NULL,
`template_id` int(11) DEFAULT NULL,
`title` varchar(255) NOT NULL,
`message` longtext NOT NULL,
`type` varchar(255) DEFAULT NULL,
`version` bigint(20) NOT NULL DEFAULT '0',
`created_at` datetime NOT NULL,
`created_by` varchar(255) NOT NULL DEFAULT 'application',
PRIMARY KEY (`id`,`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `background_version`
ADD CONSTRAINT `background_version_id_exco_content_id` FOREIGN KEY (`id`) REFERENCES `exco_content` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
CREATE TABLE IF NOT EXISTS `help_version` (
`id` int(11) NOT NULL DEFAULT '0',
`code` varchar(25) NOT NULL,
`template_id` int(11) DEFAULT NULL,
`title` varchar(255) NOT NULL,
`message` longtext NOT NULL,
`type` varchar(255) DEFAULT NULL,
`version` bigint(20) NOT NULL DEFAULT '0',
`created_at` datetime NOT NULL,
`created_by` varchar(255) NOT NULL DEFAULT 'application',
PRIMARY KEY (`id`,`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `help_version`
ADD CONSTRAINT `help_version_id_exco_content_id` FOREIGN KEY (`id`) REFERENCES `exco_content` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; |
J'avoue, c'est mystérieux pour moi.
Si quelqu'un a une piste, un conseil (même purement conceptuel) je suis preneur.
D'avance merci.