sequelize.js

Sequelize update does not work anymore: “Missing where attribute in the options parameter passed to update”

限于喜欢 提交于 2019-12-04 05:45:02
The official API documentation suggests using Model.update like this: var gid = ...; var uid = ...; var values = { gid: gid }; var where = { uid: uid }; myModel.update(values, where) .then(function() { // update callback }); But this gives me: "Missing where attribute in the options parameter passed to update". The docs also mention that this usage is deprecated. Seeing this error makes me think, they already changed it. What am I doing wrong? Apparently, the docs have not been updated yet. But the table's where row of the Model.update API docs suggests prefixing your selection with where ,

Sequelize Eager Loading Error when including related model

不羁岁月 提交于 2019-12-04 05:27:48
I'm using Sequelize to make this request: return Expense.findAll({ include: [{ model: ExpenseCategory }], }) .then(expenses => res.status(200).send(expenses)) .catch(error => res.status(500).send({ error: error })); and I'm getting this error: SequelizeEagerLoadingError I can't seem to find my error. This are my migrations for the three models (User, Expense, ExpenseCategory): queryInterface.createTable('Users', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER }, email: { allowNull: false, type: Sequelize.STRING, unique: true }, passhash: { allowNull:

Sequelize limit and offset incorrect placement in query

你。 提交于 2019-12-04 02:53:12
I am using sequelize in nodeJs and I have this code: Time_Sheet_Details.findAll({ include: [ { model: timesheetNotesSubcon, required: false, attributes:["note","file_name", "id", "working_hrs", "timestamp", "has_screenshot", "notes_category"] }, { model: Timesheet, attributes:["id","leads_id","userid"], include:[ { model: Lead_Info, attributes:["id","fname","lname","email","hiring_coordinator_id","status"], where: { hiring_coordinator_id : 326}, include:[{ model: adminInfoSchema, required: false, attributes:["admin_id","admin_fname", "admin_lname", "admin_email", "signature_contact_nos",

Node.js & MySQL - Error: 1251 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

断了今生、忘了曾经 提交于 2019-12-04 02:15:14
Right now I have only this code: const Sequelize = require('sequelize'); const sequelize = new Sequelize('database', 'root', 'passwd', { host: 'localhost', dialect: 'mysql', // http://docs.sequelizejs.com/manual/tutorial/querying.html#operators operatorsAliases: false }); sequelize .authenticate() .then(() => { console.log('Connection has been established successfully.'); }) .catch(err => { console.error('Unable to connect to the database:', err); }); But when I try to run the .js I get this error . I have already tried a lot of solutions out there, including the one I found more often but it

Sequelize Join on Non Primary Key

落爺英雄遲暮 提交于 2019-12-04 02:11:31
I have two tables I need to associate. TableA has One TableB. I'm able to do this in the TableA Model: TableA.hasOne( models.TableB, { as: 'TableB', foreignKey: 'someID' } ); Looking at the SQL, this tries to join TableA.ID and TableB.someID. What I actually want, is to join TableA.someNonPrimaryKey and TableB.someID. How can I tell sequelize to join with someNonPrimaryKey? This is not possible in sequelize at the moment, however you can try this way. Difference between HasOne and BelongsTo, HasOne inserts the association key in target model whereas BelongsTo inserts the association key in the

Sequelize limit include association

本小妞迷上赌 提交于 2019-12-04 02:08:01
I have a problem with Sequelize when limiting results and including associated models. The following produces the correct result, limited by 10 and sorted correctly. Visit.findAll({ limit: 10, order: 'updatedAt DESC', }).success(function(visits) { res.jsonp(visits); }).failure(function(err) { res.jsonp(err); }) SQL SELECT * FROM `Visits` ORDER BY updatedAt DESC LIMIT 10; However when I add an association it suddently limits on the subquery instead and thus the ordering never happens because of a limited result set. Visit.findAll({ limit: 10, order: 'updatedAt DESC', include: [ { model: Account

Dialect needs to be explicitly supplied as of v4.0.0

让人想犯罪 __ 提交于 2019-12-04 01:53:59
I have been working on a NodeJS project which uses PostgreSQL database. I am trying to implement migration to the database. Also, using Sequelize. After setting up the migration folder and config, it throws error while running db:migrate The error is: "Dialect needs to be explicitly supplied as of v4.0.0" Solution for me was based on what I had set for my NODE_ENV variable. echo $NODE_ENV If you do not have anything set for that variable, try setting it with the following: export NODE_ENV=development If a value is present, make sure you have an entry in your config file for that value. For me,

Sequelize: update in bulk

混江龙づ霸主 提交于 2019-12-04 01:29:52
I'm using Node.js, MySQL and Sequelize. I'd like to insert some 10k rows into a table at once. The table has custom primaryKey field, that is being set manually. The data are downloaded from web and are overlapping. I'd like to have a version of bulkCreate that wouldn't fail if any of the rows in data have unique keys that are already present in the table. Such kind of things is done in MySQL via INSERT ... ON DUPLICATE KEY UPDATE construct. How do I do it in Sequelize? Pass in an options object to bulkCreate with ignoreDuplicates set to true bulkCreate([...], { ignoreDuplicates: true }) Yuri

Promises in Sequelize: how to get results from each promise

亡梦爱人 提交于 2019-12-04 00:46:36
In Sequelize >=1.7 we can use promises Can you explain for me how can i get values from each user in this code: var User = sequelize.define("user", { username: Sequelize.STRING }) User .sync({ force: true }) .then(function() { return User.create({ username: 'John' }) }) .then(function(john) { return User.create({ username: 'Jane' }) }) .then(function(jane) { return User.create({ username: 'Pete' }) }) .then(function(pete) { console.log("we just created 3 users :)") console.log("this is pete:") console.log(pete.values) // what i want: console.log("this is jane:") console.log(jane.values)

How does group by works in sequelize?

流过昼夜 提交于 2019-12-03 22:05:45
I am looking for group by queries through Sequelize and cannot seem to find any documentation. SELECT column, count(column) FROM table GROUP BY column karasev issue: https://github.com/sequelize/sequelize/issues/348 User.findAll({ group: ['field'] }) i use sequelize@2.0.0-dev9 Sampat Badhe I think you looking for something like this: Table.findAll({ attributes: ['column1', sequelize.fn('count', sequelize.col('column2'))], group: ["Table.column1"] }).success(function (result) { }); Update: Newer versions of Sequelize uses .then instead of .success . Table.findAll({ attributes: ['column1',