sequelize.js

PassportJS(Local) with Sequelize and Express stuck on pending after serializing user

爷,独闯天下 提交于 2019-12-08 07:59:51
问题 I'm trying to make login work, using the tutorial I've found in http://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport--cms-21619. I modified the code to work with Sequelize. I was able to verify username and password, but after serializing a user, the page that it redirects to does not load. I was wondering if there's something I missed. I'm not really getting an error, but redirecting to /test/home page is stuck on pending, and it keeps executing a post request.

load items where relation is null in sequelize

浪尽此生 提交于 2019-12-08 05:38:44
问题 I'm new to sequelize, i'm trying to load all entries in my user table where the task relation is null. but its not working. here is what i have tried: const express = require('express'); const app = express(); const Sequelize = require('sequelize'); const sequelize = new Sequelize('sequelize', 'mazinoukah', 'solomon1', { host: 'localhost', dialect: 'postgres', pool: { max: 5, min: 0, acquire: 30000, idle: 10000, }, }); const Task = sequelize.define('Task', { name: Sequelize.STRING, completed:

Sequelize Top level where with eagerly loaded models creates sub query

放肆的年华 提交于 2019-12-08 05:14:01
问题 I'm running an into issue where Sequelize creates a subquery of the primary model and then joins the includes with that subquery instead of directly with the primary model table. The query conditions for the include(s) ends up inside the subquery's WHERE clause which makes it invalid. I have shortened names down trying to keep this compact hopefully without losing any relevant info. Environment: Nodejs: 6.11.3 Sequelize: 3.23.6 => Updated to 4.38.1 and problem persists MySql: 5.7.23 Code snip

Sequelize sytax for calling stored procedure with input parameters using MSSQL

杀马特。学长 韩版系。学妹 提交于 2019-12-08 03:12:31
问题 I'm getting an error for the code below and cannot find accurate information for the syntax to call a MSSQL store procedure through sequelize. I have also tried the syntx from the other posts on stackoverflow similar to CALL spcName(param1, ...) error: (node:14580) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SequelizeDatabaseError: Incorrect syntax near '@param1'. for code: await sequelize.query('CALL spcName(@param1, @param2, @param3, @param4);', [value1,

Select from many-to-many relationship sequelize

自古美人都是妖i 提交于 2019-12-08 02:05:43
问题 I tried to select from a table with reference another table. I have a relationship many-to-many between table food and table Ingredients. Food model: module.exports = function(sequelize, DataTypes) { return sequelize.define('food', { id: { type: DataTypes.INTEGER(10), allowNull: false, primaryKey: true, autoIncrement: true }, name_food: { type: DataTypes.STRING, allowNull: false } }, { tableName: 'food', freezeTableName: true }); }; Food_ingredients model: module.exports = function(sequelize,

How to make sequelize.js truncate the string when it exceeds the size defined in the model?

◇◆丶佛笑我妖孽 提交于 2019-12-08 00:03:45
问题 In my model I have defined a column of size 15. column: { type: Sequelize.STRING(15), allowNull: false } The input string is 28 characters, I would like to know how to sequelize.js automatically truncate the string so that only 15 characters remain. Currently I get the following error: Unhandled rejection SequelizeDatabaseError: String or binary data would be truncated. 回答1: In the configuration section of Sequelize.js there is no direct option that can be activated to truncate the characters

Sequelize.js still deletes table row even if paranoid is set to true

天涯浪子 提交于 2019-12-07 20:17:28
问题 I'm having trouble getting Sequelize.js to soft delete the rows in my table. I used Sequelize cli to do all my migrations and I'm not using the sync feature to resync the database on start. I have the timestamp fields and even the deletedAt field in my migration and models (model has paranoid: true also) and no matter what it still deletes the row instead of adding a timestamp to the deletedAt field. I noticed when do any querying it doesn't add the deletedAt = NULL in the query like I've

Sequelize one to one relation

旧城冷巷雨未停 提交于 2019-12-07 18:44:32
问题 I have two models, Video and Frame. Frame.belongsTo(models.Video); Video.hasMany(models.Frame, { as: "Frames" }); I now need a way to specify first and last frame for a video, but can't get it to work. I tried this: Video.hasOne(Frame, { as: "FirstFrame" }); Video.hasOne(Frame, { as: "LastFrame" }); but that creates FirstFrameId and LastFrameId in the Frames table instead of the Videos table. I need to have video.get/setFirstFrame() and video.get/setLastFrame() functions available. How can I

Associate different models using sequelize?

为君一笑 提交于 2019-12-07 18:41:32
问题 Hi I am trying to associate my User model with login model and Question_details models.But if i am using the Question_details association then i am geeting eagerLodingError :user is not associated to login but if i am commenting it then it works fine so how can i associate it ? But if i am associating with User Model module.exports = (sequelize, DataTypes) => { var Users = sequelize.define('users', { name: { type: DataTypes.STRING(100) } phone: { type: DataTypes.BIGINT, unique: true } }, {

Sequelize: Query same join table with different conditions

人走茶凉 提交于 2019-12-07 18:08:33
问题 I have two models Contact and Thread with a many to many relationship represented across a join table ThreadContacts . I need to write a query to find a Thread which has associations with an exact list of Contacts . For example, I might have a list of contact_id 's [1,2,3,4], and I need to find a Thread that is associated with these exact 4 contacts. I have tried including Contact on a findAll query: Thread.findOne({ include: [{ model: Contact, where: { id: $in: [1, 2, 3, 4] }, }], }) Of