How does group by works in sequelize?
issue: https://github.com/sequelize/sequelize/issues/348 User.findAll({ group: [‘field’] }) i use sequelize@2.0.0-dev9
issue: https://github.com/sequelize/sequelize/issues/348 User.findAll({ group: [‘field’] }) i use sequelize@2.0.0-dev9
The problem was due to case sensitivity and file naming. Mac OS X is case insensitive (but aware) whereas Heroku is based on Linux and is case sensitive. By running heroku run bash from my terminal, I was able to see how the /models folder appeared on Heroku’s file system. The solution was to rename … Read more
This project aims to create Sequelize models from existing schema https://github.com/sequelize/sequelize-auto Sequelize-Auto A tool to automatically generate models for SequelizeJS via the command line. Install: npm install -g sequelize-auto Usage: sequelize-auto -h <host> -d <database> -u <user> -x [password] -p [port] –dialect [dialect] -c [/path/to/config] -o [/path/to/models] Options: -h, –host IP/Hostname for the database. [required] … Read more
The solution which works for me is this:- // here startDate and endDate are Date objects const where = { from: { $between: [startDate, endDate] } }; For reference to know more about operators:- http://docs.sequelizejs.com/en/latest/docs/querying/#operators Note: In MYSQL between comparison operator is inclusive, which means it is equivalent to the expression (startDate <= from AND … Read more
You can try using db.User.destroy({ where: {}, truncate: true })
You can refer to this doc http://docs.sequelizejs.com/en/latest/docs/models-definition/#indexes You will need to change your definition like shown below and call sync var Tag = sequelize.define(‘Tag’, { id: { type: DataTypes.INTEGER(11), allowNull: false, primaryKey: true, autoIncrement: true }, user_id: { type: DataTypes.INTEGER(11), allowNull: false, }, count: { type: DataTypes.INTEGER(11), allowNull: true }, name: { type: DataTypes.STRING, allowNull: … Read more
This is more universal problem. The main difference is in semantic. you have to decide what is the relationship (Some silly example): Man has only one right arm. Right arm belongs to one man. Saying it inversely looks a little weird: Right arm has a man. A man belongs to right arm. You can have … Read more
When you do Album.belongsTo(Artist) you are creating the relation enabling you to call album.getArtist(). Artist.hasMany(Album) links the association the other way, enabling you to call artist.getAlbums(). If you only did one of those two, e.g. if you only did Album.belongsTo(Artist) you would be able to retrieve the artist of an album, but not all albums … Read more
I believe you can do: db.Page.findAll({ include: [{ model: db.Gallery include: [{ model: db.Artwork }] }], order: [ // sort by the ‘order’ column in Gallery model, in descending order. [ db.Gallery, ‘order’, ‘DESC’ ], // then sort by the ‘order’ column in the nested Artwork model in a descending order. // you need to … Read more
Example: Model.destroy({ where: { id: [1,2,3,4] }}) For more details check the API docs.