Modification modèle pour permettre d'associer une réponse à un groupe de quizs.
This commit is contained in:
parent
8e0d8fbbb0
commit
fe713480a0
@ -69,7 +69,8 @@ module.exports = (sequelize, DataTypes) =>
|
|||||||
Answer.associate = function(models)
|
Answer.associate = function(models)
|
||||||
{
|
{
|
||||||
Answer.belongsTo(models.User, { foreignKey: { name: "UserId", allowNull: false }, onDelete: 'CASCADE', onUpdate: 'CASCADE' });
|
Answer.belongsTo(models.User, { foreignKey: { name: "UserId", allowNull: false }, onDelete: 'CASCADE', onUpdate: 'CASCADE' });
|
||||||
Answer.belongsTo(models.Questionnaire, { foreignKey: { name: "QuestionnaireId", allowNull: false }, onDelete: 'CASCADE', onUpdate: 'CASCADE' });
|
Answer.belongsTo(models.Questionnaire, { foreignKey: { name: "QuestionnaireId", allowNull: true }, onDelete: 'CASCADE', onUpdate: 'CASCADE' });
|
||||||
|
Answer.belongsTo(models.Group, { foreignKey: { name: "GroupId", allowNull: true }, onDelete: 'CASCADE', onUpdate: 'CASCADE' });
|
||||||
};
|
};
|
||||||
return Answer;
|
return Answer;
|
||||||
};
|
};
|
@ -88,6 +88,7 @@ module.exports = (sequelize, DataTypes) =>
|
|||||||
Group.associate = function(models)
|
Group.associate = function(models)
|
||||||
{
|
{
|
||||||
Group.hasMany(models.Questionnaire);
|
Group.hasMany(models.Questionnaire);
|
||||||
|
Group.hasMany(models.Answer);
|
||||||
Group.belongsTo(models.User, { as: "Creator", foreignKey: { name: "CreatorId", allowNull: false } });
|
Group.belongsTo(models.User, { as: "Creator", foreignKey: { name: "CreatorId", allowNull: false } });
|
||||||
};
|
};
|
||||||
return Group;
|
return Group;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
-- https://www.phpmyadmin.net/
|
-- https://www.phpmyadmin.net/
|
||||||
--
|
--
|
||||||
-- Client : localhost:3306
|
-- Client : localhost:3306
|
||||||
-- Généré le : Mer 21 Octobre 2020 à 17:36
|
-- Généré le : Mer 21 Octobre 2020 à 17:55
|
||||||
-- Version du serveur : 5.7.31-0ubuntu0.18.04.1
|
-- Version du serveur : 5.7.31-0ubuntu0.18.04.1
|
||||||
-- Version de PHP : 7.2.24-0ubuntu0.18.04.7
|
-- Version de PHP : 7.2.24-0ubuntu0.18.04.7
|
||||||
|
|
||||||
@ -33,7 +33,8 @@ CREATE TABLE `Answers` (
|
|||||||
`duration` int(5) UNSIGNED DEFAULT NULL,
|
`duration` int(5) UNSIGNED DEFAULT NULL,
|
||||||
`createdAt` datetime NOT NULL,
|
`createdAt` datetime NOT NULL,
|
||||||
`UserId` int(11) NOT NULL,
|
`UserId` int(11) NOT NULL,
|
||||||
`QuestionnaireId` int(11) NOT NULL
|
`QuestionnaireId` int(11) DEFAULT NULL,
|
||||||
|
`GroupId` int(11) DEFAULT NULL
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
@ -273,7 +274,8 @@ CREATE TABLE `Users` (
|
|||||||
ALTER TABLE `Answers`
|
ALTER TABLE `Answers`
|
||||||
ADD PRIMARY KEY (`id`),
|
ADD PRIMARY KEY (`id`),
|
||||||
ADD KEY `UserId` (`UserId`),
|
ADD KEY `UserId` (`UserId`),
|
||||||
ADD KEY `QuestionnaireId` (`QuestionnaireId`);
|
ADD KEY `QuestionnaireId` (`QuestionnaireId`),
|
||||||
|
ADD KEY `GroupId` (`GroupId`);
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Index pour la table `Choices`
|
-- Index pour la table `Choices`
|
||||||
@ -442,7 +444,7 @@ ALTER TABLE `Tags`
|
|||||||
-- AUTO_INCREMENT pour la table `UserDeleteds`
|
-- AUTO_INCREMENT pour la table `UserDeleteds`
|
||||||
--
|
--
|
||||||
ALTER TABLE `UserDeleteds`
|
ALTER TABLE `UserDeleteds`
|
||||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT pour la table `Users`
|
-- AUTO_INCREMENT pour la table `Users`
|
||||||
--
|
--
|
||||||
@ -457,7 +459,8 @@ ALTER TABLE `Users`
|
|||||||
--
|
--
|
||||||
ALTER TABLE `Answers`
|
ALTER TABLE `Answers`
|
||||||
ADD CONSTRAINT `Answers_ibfk_7` FOREIGN KEY (`UserId`) REFERENCES `Users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
ADD CONSTRAINT `Answers_ibfk_7` FOREIGN KEY (`UserId`) REFERENCES `Users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
ADD CONSTRAINT `Answers_ibfk_8` FOREIGN KEY (`QuestionnaireId`) REFERENCES `Questionnaires` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
ADD CONSTRAINT `Answers_ibfk_8` FOREIGN KEY (`QuestionnaireId`) REFERENCES `Questionnaires` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
ADD CONSTRAINT `Answers_ibfk_9` FOREIGN KEY (`GroupId`) REFERENCES `Groups` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Contraintes pour la table `Choices`
|
-- Contraintes pour la table `Choices`
|
||||||
|
Loading…
Reference in New Issue
Block a user