sequelize.js

sequelize - Cannot add foreign key constraint

扶醉桌前 提交于 2020-05-25 06:43:49
问题 I'm trying to set a 1:1 relation between two tables. RefreshToken table will have two foreignKey releated to Users table, as in this image: I used sequelize-auto to generate my sequelize models. Users model: module.exports = function(sequelize, DataTypes) { return sequelize.define('Users', { idUsers: { type: DataTypes.INTEGER(11), allowNull: false, primaryKey: true }, name: { type: DataTypes.STRING(45), allowNull: true }, mail: { type: DataTypes.STRING(45), allowNull: false, primaryKey: true

How to create a TRIGGER in SEQUELIZE (nodeJS)?

一曲冷凌霜 提交于 2020-05-24 21:18:08
问题 I'm trying to create a trigger using sequelize.. the main idea is to create an instance of CONFIG after creating a USER . // USER MODEL module.exports = function(sequelize, DataTypes) { var User = sequelize.define('User', { name : DataTypes.STRING(255), email : DataTypes.STRING(255), username : DataTypes.STRING(45), password : DataTypes.STRING(100), }, { classMethods : { associate : function(models) { User.hasOne(models.Config) } } }); return User; }; // CONFIG MODEL module.exports = function

sequelize.js custom validator, check for unique username / password

不问归期 提交于 2020-05-24 17:52:33
问题 Imagine I have defined the following custom validator function: isUnique: function () { // This works as expected throw new Error({error:[{message:'Email address already in use!'}]}); } However, when I attempt to query the DB I run into problems: isUnique: function (email) { // This doesn't work var User = seqeulize.import('/path/to/user/model'); User.find({where:{email: email}}) .success(function () { // This gets called throw new Error({error:[{message:'Email address already in use!'}]}); /

Sequelize Model is not associated with model

霸气de小男生 提交于 2020-05-17 06:26:31
问题 I've been spending hours for nothing. I've had so many sources, they are all kinda the same, but I just couldn't make my project work. This question Sequelize.js - "is not associated to" is so much the same to mine, BUT, this question of mine shouldn't be a duplicate. Because it has certainly a new issue! To list down my sources, the ones that I've read thoroughly and tried out: Sequelize.js - "is not associated to" Sequelize 4.3.2 n:m (many-to-many) association: Unhandled rejection

Sequelize Model is not associated with model

两盒软妹~` 提交于 2020-05-17 06:26:29
问题 I've been spending hours for nothing. I've had so many sources, they are all kinda the same, but I just couldn't make my project work. This question Sequelize.js - "is not associated to" is so much the same to mine, BUT, this question of mine shouldn't be a duplicate. Because it has certainly a new issue! To list down my sources, the ones that I've read thoroughly and tried out: Sequelize.js - "is not associated to" Sequelize 4.3.2 n:m (many-to-many) association: Unhandled rejection

Load attributes from associated model in sequelize.js

♀尐吖头ヾ 提交于 2020-05-15 17:44:54
问题 I have two models. User and Manager User Model const UserMaster = sequelize.define('User', { UserId: { type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true }, RelationshipId: { type: DataTypes.STRING, allowNull: true, foreignKey: true }, UserName: { type: DataTypes.STRING, allowNull: true } }) Manager model const Manager = sequelize.define('Manager', { ManagerId: { type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true }, RelationshipId: {

Load attributes from associated model in sequelize.js

人走茶凉 提交于 2020-05-15 17:44:39
问题 I have two models. User and Manager User Model const UserMaster = sequelize.define('User', { UserId: { type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true }, RelationshipId: { type: DataTypes.STRING, allowNull: true, foreignKey: true }, UserName: { type: DataTypes.STRING, allowNull: true } }) Manager model const Manager = sequelize.define('Manager', { ManagerId: { type: DataTypes.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true }, RelationshipId: {

sequelize.sync({ force: true }) is not working some times

╄→гoц情女王★ 提交于 2020-05-15 05:19:24
问题 i am using gulp tasks for migration of database. For testing purpose i am using different database. so i need exactly same database. i am trying to do with sequelize.sync({ force: true }) but its not working. i am having my all models in portal-model. here is the code: const models = require('portal-models'); gulp.task('migrate', ['create-database'], (done) => { models.sequelize.query('SET FOREIGN_KEY_CHECKS = 0') .then(() => models.sequelize.sync({ force: true, alter: true })) .... .... ....

sequelize.sync({ force: true }) is not working some times

久未见 提交于 2020-05-15 05:19:06
问题 i am using gulp tasks for migration of database. For testing purpose i am using different database. so i need exactly same database. i am trying to do with sequelize.sync({ force: true }) but its not working. i am having my all models in portal-model. here is the code: const models = require('portal-models'); gulp.task('migrate', ['create-database'], (done) => { models.sequelize.query('SET FOREIGN_KEY_CHECKS = 0') .then(() => models.sequelize.sync({ force: true, alter: true })) .... .... ....

Sequelize many to many with extra columns

你。 提交于 2020-05-12 10:49:37
问题 After some research I didn't find anything related to my problem. So the setting is an M:M relationship already working with sequelize (sqllite): return User.find({ where: { _id: userId } }).then(user => { logger.info(`UserController - found user`); Notification.find({ where: { _id: notificationId } }).then(notification => { if (associate) { return user.addNotification([notification]); } else { return user.removeNotification([notification]); } }) }) The thing is that I have extra fields in