sequelize.js

Sequelize: Error: Error: Table1 is not associated to Table2

巧了我就是萌 提交于 2020-01-11 08:13:11
问题 I am trying to create the following associations using sequelize but I keep getting the following error “Error: Error: customer is not associated to order!”. I have bi-directional associations according to what I found in the documentation. I am confused about what the problem could be because when I look into the database tables I can see the foreign keys. For this example, I am trying to pull the order and customer associated with the particular order. Technically, I could do three seaprate

How can I see the SQL generated by Sequelize.js?

℡╲_俬逩灬. 提交于 2020-01-08 16:52:05
问题 I want to see the SQL commands that are sent to the PostgreSQL server because I need to check if they are correct. In particular, I am interested in the table creation commands. For instance, ActiveRecord (Ruby) prints its SQL statements to standard output. Is this possible with Node.js/ActionHero.js and Sequelize.js as well? 回答1: You can pass a logging option when initializing sequelize, which can either be a function or console.log var sequelize = new Sequelize('database', 'username',

Sequelize and Node.js: Initializing Multiple Databases On One Server Programmatically

岁酱吖の 提交于 2020-01-07 03:11:09
问题 When I run the server attempting to create two databases (db1 and db2), the system kicks backs this error: Possibly unhandled SequelizeBaseError: database "db2" does not exist As a reference, there is similar stackoverflow question on this topic here, however, the author of the solution does not cover the solution to how the server.js file is setup. You will notice I have structured my index.js file similar to their answer. My models/index.js file and server run and executes scripts properly,

Sequelize Issue By Separating Model Logic from Model Configuration

故事扮演 提交于 2020-01-06 21:25:53
问题 I am following the sequelize best practices by connecting to a host and importing all models into one file and then calling that file when interacting the model. For some reason it looks like this is causing an issue as I am getting an error at using the define method for the sequelize variable and I ran a test with a file that contained both logic together and I was able to add a user. Error: TypeError: Cannot read property 'define' of undefined at new module.exports (/Users/user/Desktop

Sequelize Issue By Separating Model Logic from Model Configuration

六月ゝ 毕业季﹏ 提交于 2020-01-06 21:25:24
问题 I am following the sequelize best practices by connecting to a host and importing all models into one file and then calling that file when interacting the model. For some reason it looks like this is causing an issue as I am getting an error at using the define method for the sequelize variable and I ran a test with a file that contained both logic together and I was able to add a user. Error: TypeError: Cannot read property 'define' of undefined at new module.exports (/Users/user/Desktop

Using Transaction in Sequelize for Postgres

余生长醉 提交于 2020-01-06 20:07:42
问题 I am trying the transaction for sequelize in noodejs. I am using postgres as my database. When I call the testDel the transaction get autocommitted in the testDel. Even if transaction autocommit already set to false. If I pass the variable t from the Db.transaction to testDel, then it will wait for the manual commit / rollback. Can I do without passing t into function? It make coding very complicated. The coding is as following: Db.transaction({autocommit: false}).then((t) => { args =

Sequelize Many to Many Query Issue

你。 提交于 2020-01-06 06:02:42
问题 So, I have an existing MySQL database that I'm trying to connect to with Sequelize in Node that has a products table, a categories table and a categories_products table. What I want to do is return products, with each product containing all of the categories it belongs to. Here's what I've got: // Declare Product Model const Product = sequelize.define('products', { name: Sequelize.STRING, description: Sequelize.STRING, single_price: Sequelize.BOOLEAN, oz_price: Sequelize.FLOAT, half_price:

Sequelize query Or-ing where and include statements

风格不统一 提交于 2020-01-06 05:54:10
问题 I am trying make a Sequelize query that returns only records that match a where clause or include wheres . For example I have a user model that belongs to a person model. The user model has one field called username and the person model has a first and last name. Example Query: { "where": { "username": { "$iLike": "%s%" } }, "include": [{ "model": Person, "where": { "$or": [{ "firstName": { "$iLike": "%s%" } }, { "lastName": { "$iLike": "%s%" } }] } }] } The query above matches records that

Sequelize query Or-ing where and include statements

蓝咒 提交于 2020-01-06 05:54:04
问题 I am trying make a Sequelize query that returns only records that match a where clause or include wheres . For example I have a user model that belongs to a person model. The user model has one field called username and the person model has a first and last name. Example Query: { "where": { "username": { "$iLike": "%s%" } }, "include": [{ "model": Person, "where": { "$or": [{ "firstName": { "$iLike": "%s%" } }, { "lastName": { "$iLike": "%s%" } }] } }] } The query above matches records that

Sequelize - ForeignKey relationship - problem with alias

时光怂恿深爱的人放手 提交于 2020-01-06 05:25:13
问题 I have two tables. One is skills, another is ratings. My problem is specific to ratings: The model of ratings is: var sequelize = require('../sequelizeConfig'); var Sequelize = require('sequelize'); var Ratings=sequelize.define('ratings',{ ratingID:{ type:Sequelize.BIGINT, field:'rating_id', primaryKey:true }, empID:{ type: Sequelize.STRING, field:'emp_id' }, skillID:{ type:Sequelize.STRING, field:'skill_id', references: { model: 'skills', key: 'skill_id' } }, rating:{ type: Sequelize.BIGINT