sequelize.js

Sequelize: Include.where filtering by a 'parent' Model attribute

大憨熊 提交于 2020-06-09 11:55:16
问题 I have two Models related, Catalog and ProductCategory. The latter has a composed PK, 'id, language_id'. Here are the models simplified: var Catalog = sequelize.define("Catalog", { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, user_id: { type: DataTypes.INTEGER, allowNull: false }, product_category_id: { type: DataTypes.STRING(7) }, language_id: { type: DataTypes.INTEGER }, ... more stuff ... } var ProductCategory = sequelize.define("ProductCategory", { id: { type:

Sequelize Where statement with date

倖福魔咒の 提交于 2020-06-08 04:39:29
问题 I am using sequelize as my backend ORM. Now i wish to do some where operations on a Date. More Speceficly i want to get all data where a date is from now and 7 days back. The problem is that the documentation does not specify which operations you can do on Datatypes.DATE Can anyone point me in the right direction? 回答1: Just like Molda says, you can use $gt , $lt , $gte or $lte with a date: model.findAll({ where: { start_datetime: { $gte: moment().subtract(7, 'days').toDate() } } }) If you're

Sequelize error: defineCall not defined in Index.js

假如想象 提交于 2020-05-29 03:59:02
问题 I've been receiving this sequelize error /node_modules/sequelize/lib/sequelize.js:508 this.importCache[path] = defineCall(this, DataTypes); ^ TypeError: defineCall is not a function at module.exports.Sequelize.import (/node_modules/sequelize/lib/sequelize.js:508:32) at /models/Index.js:16:33 at Array.forEach (native) at Object.<anonymous> (/Users/vincentporta/Desktop/RCB_Classwork/cesarcell/models/Index.js:15:4) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js

Sequelize error: defineCall not defined in Index.js

送分小仙女□ 提交于 2020-05-29 03:56:10
问题 I've been receiving this sequelize error /node_modules/sequelize/lib/sequelize.js:508 this.importCache[path] = defineCall(this, DataTypes); ^ TypeError: defineCall is not a function at module.exports.Sequelize.import (/node_modules/sequelize/lib/sequelize.js:508:32) at /models/Index.js:16:33 at Array.forEach (native) at Object.<anonymous> (/Users/vincentporta/Desktop/RCB_Classwork/cesarcell/models/Index.js:15:4) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js

Sequelize optional where clause parameters?

你离开我真会死。 提交于 2020-05-28 21:59:43
问题 This is one thing that really annoys me! I have to write 2 different functions for almost the same query! Say I've got an API that returns posts that are associated to a particular typeId and cityId . To get ALL posts that are associated to typeId 1 OR 2, OR 3 and cityId 1 I would parse the following to my sequelize findAll query: $or: [{typeId: 1}, {typeId: 2}, {typeId: 3}] cityId: 1 But say I want to get all post where cityId = 1 andOr typeId = 1,2,3,4,5,6,7,8,9,10,etc... I cannot do

Is there no option to map the column name in sequelize model

社会主义新天地 提交于 2020-05-26 10:28:38
问题 I have a given database with long, cumbersome columnnames. Isn't there any way to map the tablenames to shorter and more descriptive propertyNames in the model ? something like var Employee = sql.define('Employee', { id : {type : Sequelize.INTEGER , primaryKey: true, map : "veryLongNameForJustTheId"} },{ tableName: 'cumbersomeTableName', timestamps: false });; 回答1: id : { field: 'some_long_name_that_is_terrible_thanks_dba_guy', type : Sequelize.INTEGER , primaryKey: true } Specify a 'field'

Is there no option to map the column name in sequelize model

心已入冬 提交于 2020-05-26 10:27:08
问题 I have a given database with long, cumbersome columnnames. Isn't there any way to map the tablenames to shorter and more descriptive propertyNames in the model ? something like var Employee = sql.define('Employee', { id : {type : Sequelize.INTEGER , primaryKey: true, map : "veryLongNameForJustTheId"} },{ tableName: 'cumbersomeTableName', timestamps: false });; 回答1: id : { field: 'some_long_name_that_is_terrible_thanks_dba_guy', type : Sequelize.INTEGER , primaryKey: true } Specify a 'field'

Sequelize: Find All That Match Contains (Case Insensitive)

半世苍凉 提交于 2020-05-25 14:54:03
问题 I want to use sequelize.js to query a model for records with a contains restraint. How do I do that? This is what I have right now: Assets .findAll({ limit: 10, where: ["asset_name like ?", '%' + request.body.query + '%'] }) .then(function(assets){ return response.json({ msg: 'search results', assets: assets }); }) .catch(function(error){ console.log(error); }); but I get the following error: { error: operator does not exist: character varying @> unknown at Connection.parseE (/home/travellr

Sequelize: Find All That Match Contains (Case Insensitive)

一个人想着一个人 提交于 2020-05-25 14:52:29
问题 I want to use sequelize.js to query a model for records with a contains restraint. How do I do that? This is what I have right now: Assets .findAll({ limit: 10, where: ["asset_name like ?", '%' + request.body.query + '%'] }) .then(function(assets){ return response.json({ msg: 'search results', assets: assets }); }) .catch(function(error){ console.log(error); }); but I get the following error: { error: operator does not exist: character varying @> unknown at Connection.parseE (/home/travellr

Sequelize: Find All That Match Contains (Case Insensitive)

巧了我就是萌 提交于 2020-05-25 14:52:02
问题 I want to use sequelize.js to query a model for records with a contains restraint. How do I do that? This is what I have right now: Assets .findAll({ limit: 10, where: ["asset_name like ?", '%' + request.body.query + '%'] }) .then(function(assets){ return response.json({ msg: 'search results', assets: assets }); }) .catch(function(error){ console.log(error); }); but I get the following error: { error: operator does not exist: character varying @> unknown at Connection.parseE (/home/travellr