sequelize.js

Sequelize - double joining table on two IDs

只谈情不闲聊 提交于 2019-12-11 11:40:50
问题 If I have a "Users" table and a "Followings" table ("Followings" has UserId and FollowedId, both refer to users on the "Users" table) "Followings" is basically when one user "follows" another user How do I set up the associations so that when I use the Followings Model to query and include the Users model, it will include nested info for BOTH columns? Example: Users | id | name | email | etc | Followings | id | UserId | FollowedId | UserId and FollowedId are both assciated to users on "Users"

Three way relationship

烂漫一生 提交于 2019-12-11 11:12:10
问题 Creating the following relationships bookmark.belongsToMany(tag, {through: 'BookmarkTag'}); user.belongsToMany(bookmark, {through: 'UserBookmark'}); Will create two relationshiptables BookmarkTag |bookmarkId|tagId UserBookmark |bookmarkId|userId i would like BookmarkTag to contain user id aswell so that i know which user added a tag to which bookmark BookmarkTag |bookmarkId|tagId|userId is that possible through sequelize associations fullcode var bookmark = sequelize.define('Bookmark', { name

Sequelize findOrCreate falling back to catch if data is found

若如初见. 提交于 2019-12-11 10:46:09
问题 FindOrCreate is suppose to either find or create based on the arguments you give it. So I'm wondering why it's falling back to the catch promise when data (a user) is found, when it should just return the data that was found to the .spread function instead of trying to insert the data that already exists?!. As you can see below if there is a user found or created it's going to run the same function regardless. All that function is doing is creating an auth token for the particular user. But

Sequelize Error: Relation does not exist

二次信任 提交于 2019-12-11 10:45:39
问题 I am able to use sequelize.js to do an INSERT INTO command for a table in my development database, but not in my test database. Despite researching thoroughly, I have not been able to resolve the issue. A similar question has been posted here, though I have not been able to answer my question with the answers: sequelize with postgres database not working after migration from mysql Here is my relevant migration file: 'use strict'; module.exports = { up: (queryInterface, Sequelize) => { return

Express .map function not returning values

故事扮演 提交于 2019-12-11 10:42:49
问题 I have some jquery in my view file where I want to take all of the values of the individual fields with the name, discoverySource . The solution thanks to some help from a stack user was to use the lodash module and then map the array into individual values to be appropriately used for my sequelize BulkCreate function. With my current post setup, the .map method correctly creates individual rows in my db based on the amount of fields filled in, but for some reason the values aren't being

sequelize beforeSave hook not firing

落花浮王杯 提交于 2019-12-11 10:09:59
问题 I've generated models with sequelize-auto, and need to use a beforeSave hook (see here). The hook isn't firing as far as I can tell. sequelize version ^4.20.1, sequelize-auto version ^0.4.29, express version ~4.15.5. Can anyone help? module.exports = function(sequelize, DataTypes) { return sequelize.define('trad', { id: { type: DataTypes.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, geom: { type: DataTypes.GEOMETRY('POINT', 4326), allowNull: true }, ... }, { hooks: {

Sequelize Migration: relation <table> does not exist

坚强是说给别人听的谎言 提交于 2019-12-11 08:55:57
问题 I'm working through an Author hasMany Books example and am attempting to run a sequelize-cli migration, but am getting the following issue when I run the following migration: ERROR: relation "authors" does not exist This is the first migration to create an author: 'use strict'; module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.createTable('Authors', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER }, firstName: { type:

Deploying Node/Sequelize app to heroku - Issue with PORT

青春壹個敷衍的年華 提交于 2019-12-11 08:39:47
问题 I'm building a Node/Postgres app that I'm deploying to heroku. I'm receiving a timeout error while trying to open the app in production. According to Heroku, the error I'm receiving comes from database or port connection issues. I believe my database connection is fine, I'm getting a log that the connection was successful. Unsure if my integration with postgres caused a PORT connection issue. Here is the error on heroku logs (not very helpful) 2017-07-20T17:44:53.432603+00:00 heroku[web.1]:

Updating multiple records using sequelize and nodejs?

谁说我不能喝 提交于 2019-12-11 07:58:13
问题 Using node.js (v0.10.12) and sequelize (2.0.0-dev9), I am wanting to update attributes within an existing database table. From anther SO discussion I am able to update only one record at a time. I encapsulated the call in a for loop but that updated the same record throughout the for loop. Could someone help me modify this code to update all records that match the search requirements? Below is my code: global.db.Task.find({ where: {"Cd": "match"} && {"Desc": null} }).on('success', function

Nodejs with sequelize couldn't create table in mysql workbench after starting the server

冷暖自知 提交于 2019-12-11 07:19:14
问题 I started to learn how to build Rest API using Nodejs , Expressjs , Sequelize and MySQL using Mysqlworkbench . My Problem: After I start the server, the table is not created by Sequelize and no table in Mysqlworkbench also. Just this message appeared below... Thanks for any guide or help in advance:- Sequelize { options: { dialect: 'mysql', dialectModulePath: null, host: 'localhost', protocol: 'tcp', define: {}, query: {}, sync: {}, timezone: '+00:00', logging: [Function: bound consoleCall],