sequelize.js

self.$expandAttributes is not a function with Sequelize

心已入冬 提交于 2019-12-10 15:46:09
问题 i've try to add master and details object to MySQL with Sequelize and i got the error like; TypeError: self.$expandAttributes is not a function at conformOptions (/Desktop/git/ss-portal-server/node_modules/sequelize/lib/model.js:243:10) at conformInclude (/Desktop/git/ss-portal-server/node_modules/sequelize/lib/model.js:300:5) Reference from; https://github.com/sequelize/sequelize/blob/master/docs/docs/associations.md Anyone know where is my error. Many thanks Sample code; var contactModel =

Sequelize cast column to integer in where clause

*爱你&永不变心* 提交于 2019-12-10 15:37:44
问题 Trying to cast a column inside a where clause to search for a query against. Have a difficult time finding reliable documentation on how to do this. Any ideas? return await User.findAndCountAll({ where: { [Op.or]: { 'email': { [Op.iLike]: `%${query}%` }, '$id::text$': { [Op.iLike]: `%${query}%` } // id is int but needs to be string for searching } }, limit, offset: page * limit, order: [[sortBy, sortOrder.toUpperCase()]], raw: true, logging: console.log }); 回答1: I think this is what you

Finding sum and grouping in sequelize

∥☆過路亽.° 提交于 2019-12-10 15:13:45
问题 I have a donations table as follows. Donations Table | id| amount | member_id | |---|--------|-----------| | 0 | 500 | 01| | 1 | 1000 | 02| | 2 | 2000 | 01| How to find sum and group the table by member id as follows. | amount | member_id | |--------|-----------| | 2500 | 01| | 1000 | 02| I tried to use the following code but it doesnt seem to work. const salesValue = await DONATIONS.sum('amount', { group: 'member_id' }); 回答1: const totalAmount = await DONATIONS.findAll({ attributes: [

Sequelize query - compare dates in two columns

…衆ロ難τιáo~ 提交于 2019-12-10 13:49:45
问题 I have a table in Sequelize with two date columns - i.e. with : var Visit = sequelize.define("Visit", { /*...*/ scheduleEndDate: { type: DataTypes.DATE } actualEndDate: { type: DataTypes.DATE } /*...*/ }); I want to make a query that returns rows where actualEndDate is before scheduleEndDate - and can't get the format right. What I've tried for the where part of my findAll query is: where: { actualEndDate: { lt: Visit.scheduleEndDate } } - throws an error because Visit not defined (have also

-bash: sequelize: command not found

Deadly 提交于 2019-12-10 13:35:55
问题 I just ran npm install --save sequelize pg pg-hstore in my project root directory and now I am unable to invoke sequelize init. I get the error: -bash: sequelize: command not found. What am I doing wrong? 回答1: The reason is: sequelize is not installed globally on your cli. To get sequelize access to all your cli just do. npm install -g sequelize-cli The '-g' means global this will allow you to access sequelize command anywhere in your app directory. After that you can do eg: sequelize model

Sequelize returns join table in query

会有一股神秘感。 提交于 2019-12-10 13:35:12
问题 I've got a many-to-many relation in my MSQL table between these two model: Venue - Representing a venue which can have multiple owners (employees) Employee - Representing an employee which can be either a ceo or sales employee or whatsoever. I am using sequelize to set up the relations like so: Relation Employee > Venue Employee.associate = function (models) { models.Employee.belongsToMany(models.Venue, { through: 'EmployeeVenues' }) } Relation Venue > Employee Venue.associate = function

Node/Sequelize: loading all models

最后都变了- 提交于 2019-12-10 11:46:59
问题 I have 4 models in the models folder (artisans, stores, items and itemStores,) but it only loads the items model into the db variable. Why might this be? server.js var express = require('express'); var app = express(); var bodyParser = require('body-parser'); var db = require('./models'); var artisans = require('./app/routes/artisans.js'); var stores = require('./app/routes/stores.js'); var items = require('./app/routes/items.js'); var itemStores = require('./app/routes/itemStores.js'); var

Calling stored procedure in sequalize passing in a parameter

感情迁移 提交于 2019-12-10 11:40:03
问题 I'm trying to call a stored procedure passing in a parameter as shown below. However, I know my syntax is off and I don't see any examples doing this, either in the docs or unit tests. model.sequelize.query('CALL truncate_tables(\'appuser\');') .then(function (response) { done(); }).error(function (err) { done(err); }); suggestions? I started off looking at this link. Calling stored procedures in Sequelize.js Additional info: here is the error I am seeing Unhandled rejection

Sequelize WHERE sequelize.fn(…) AND something='something' ordering issue

a 夏天 提交于 2019-12-10 10:49:58
问题 I have a Sequelize findOne function that looks to select a row where the given point intersects a polygon (col 'geom') AND status = 'active'. var point = sequelize.fn('ST_GeomFromText', 'POINT(' + lng + ' ' + lat +')', 4326); var intersects = sequelize.fn('ST_Intersects', sequelize.col('geom'), point); GeoCounty.findOne({ attributes: ['id', 'name' ], where: { status: 'active', $and: intersects }, plain: true }) As of right now, it works just fine. It produces SQL that looks like: SELECT "id",

Sequelize Many to Many failing with 'is not associated to' when trying to associate entries?

独自空忆成欢 提交于 2019-12-10 10:49:49
问题 I am having a problem with my many to many configuration with Sequelize, where it complains that site_article_keyword is not associated to article_keyword . The code below represents a minimal test case to try to understand what I am doing wrong (I hoped to provide something smaller, but this is what I have). I am using bluebird for the Promise API. const Sequelize = require('sequelize'); var sequelize = new Sequelize(undefined, undefined, undefined, { dialect: 'sqlite', storage: '.