sequelize.js

Sequelize reads datetime in UTC only

谁说胖子不能爱 提交于 2019-12-21 21:35:55
问题 I have set the timezone option to my timezone ( Europe/Zagreb and I've tried with +01:00 too), and the time is saved as it should be, however, when reading the time from the database, Sequelize converts it to UTC. I have tried different timezones too, each is saved correctly, but always converted to UTC when read from database. Am I doing something wrong or is this a known issue and are there any workarounds? I create a new connection with: sequelize = new Sequelize(config.database, config

Sequelize table name change

两盒软妹~` 提交于 2019-12-21 17:03:04
问题 Have renamed a table from users to user in MySQL database. In Express I'm running Sequelize and created a schema for the old users table. With the table renamed and everything in the code changed from users to user , Sequelize is still looking for a table named specifically users even though the table name is updated in the schema. User = db.sequelize.define('user', { first_name: Sequelize.STRING, last_name: Sequelize.STRING, email: Sequelize.STRING, password: Sequelize.STRING, role:

Sequelize table name change

不羁岁月 提交于 2019-12-21 17:01:47
问题 Have renamed a table from users to user in MySQL database. In Express I'm running Sequelize and created a schema for the old users table. With the table renamed and everything in the code changed from users to user , Sequelize is still looking for a table named specifically users even though the table name is updated in the schema. User = db.sequelize.define('user', { first_name: Sequelize.STRING, last_name: Sequelize.STRING, email: Sequelize.STRING, password: Sequelize.STRING, role:

How does group by works in sequelize?

大兔子大兔子 提交于 2019-12-21 06:46:29
问题 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 回答1: issue: https://github.com/sequelize/sequelize/issues/348 User.findAll({ group: ['field'] }) i use sequelize@2.0.0-dev9 回答2: 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

Associations in sequelize not working as intended

混江龙づ霸主 提交于 2019-12-21 05:46:10
问题 I am attempting to output a nested relation where Cat.hasMany(legs) Leg.belongsTo(cat) Leg.hasOne(paw) paw.hasMany(leg) Here is my Cat Model: module.exports = (sequelize, DataTypes) => { const Cat = sequelize.define('Cat', { userId: { type: DataTypes.STRING, }, }, {}); Cat.associate = function (models) { Cat.hasMany(models.Leg, { foreignKey: 'catId', as: 'legs', }); }; return Cat; }; My Legs Model: module.exports = (sequelize, DataTypes) => { const Leg = sequelize.define('Leg', {

Sequelize: seed with associations

纵然是瞬间 提交于 2019-12-21 04:23:07
问题 I have 2 models, Courses and Videos, for example. And Courses has many Videos. // course.js 'use strict'; module.exports = (sequelize, DataTypes) => { const Course = sequelize.define('Course', { title: DataTypes.STRING, description: DataTypes.STRING }); Course.associate = models => { Course.hasMany(models.Video); }; return Course; }; // video.js 'use strict'; module.exports = (sequelize, DataTypes) => { const Video = sequelize.define('Video', { title: DataTypes.STRING, description: DataTypes

sequelize fetching associations on find (1.6)

帅比萌擦擦* 提交于 2019-12-21 03:38:21
问题 sequelize 1.6 has the following in the changelog: [FEATURE] added association prefetching for find and findAll The question is HOW? I have the following models defined: var self = { Medium: client.define("Medium", { name: Sequelize.STRING, description: Sequelize.TEXT }, User: client.define("User", { firstName: Sequelize.STRING, lastName: Sequelize.STRING, email: Sequelize.STRING, aboutArt: Sequelize.TEXT, bio: Sequelize.TEXT, password: Sequelize.STRING, description: Sequelize.TEXT } }; self

Should Sequelize migrations update model files?

六眼飞鱼酱① 提交于 2019-12-20 20:02:35
问题 Are Sequelize migrations supposed to keep your model files in line with your database? I used the sequelize cli to bootstrap a simple project and create a model node_modules/.bin/sequelize model:generate --name User --attributes email:string . I migrated this with no issue. Then I created the following migration file to add a notNull constraint to the user email attribute. updateEmail migration const models = require("../models") module.exports = { up: (queryInterface, Sequelize) => { return

How can use LEFT JOIN at Sequelize?

こ雲淡風輕ζ 提交于 2019-12-20 17:39:55
问题 Relations: Shop.hasMany(ShopAd, {foreignKey : 'shop_id', as : 'ads'}); ShopAd.belongsTo(Shop, {foreignKey : 'id'}) I using : Shop.findAll({where:{id:shopId}, include:[{model:ShopAd, as:'ads', where:{is_valid:1, is_vertify:1}}]}).success(function(result) { callback(result); }); But the sql is : SELECT `Shop`.`id`, `Shop`.`user_id`, `Shop`.`short_name`, `Shop`.`description`, `Shop`.`tips`, `Shop`.`city`, `Shop`.`province`, `Shop`.`address`, `Shop`.`logo`, `Shop`.`publicity_photo`, `Shop`.

GraphQL queries with tables join

江枫思渺然 提交于 2019-12-20 09:51:16
问题 I am learning GraphQL so I built a little project. Let's say I have 2 models, User and Comment . const Comment = Model.define('Comment', { content: { type: DataType.TEXT, allowNull: false, validate: { notEmpty: true, }, }, }); const User = Model.define('User', { name: { type: DataType.STRING, allowNull: false, validate: { notEmpty: true, }, }, phone: DataType.STRING, picture: DataType.STRING, }); The relations are 1:many, where a user can have many comments. I have built the schema like this: