sequelize.js

Sequelize :: Limit and Order INSIDE an Include[] construct

可紊 提交于 2019-12-06 22:55:54
问题 I have the following model hierarchy: User.hasMany(Child); Child.hasMany(Profile); Once I have a User object loaded, I need to load its Children and their associated Profiles according to the following logic: Load all Children for the User , sorted by name . For each Child , load the first three Profiles reverse sorted by id . Is there a way to limit and sort the eager-loaded Profiles ? I can limit and sort the Children but not the Profiles . user.getChildren({ limit: 10, order: [['name',

Remove constraints in sequelize migration

为君一笑 提交于 2019-12-06 19:30:01
问题 I'm adding a unique constraint in a migration via the migrations.changeColumn function. Adding the constraint works, but since you need to provide a “backwards migration“, removing it the same way does not. It doesn't give any errors when migrating backwards, but again applying the forward migration results in Possibly unhandled SequelizeDatabaseError: relation "myAttribute_unique_idx" already exists . (The used database is postgres) module.exports = { up: function (migration, DataTypes, done

sequelize Model.hasOne Error: Model is not associated to ModelTwo

随声附和 提交于 2019-12-06 17:00:50
问题 I've integrated sequelizejs into my express framework. I got all the models configured and was trying to build my first query with it. I keep getting the error "Error: Model is not associated to ModelTwo!" app.get('/',function(req,res){ db.Member.findAll({include:[{model:db.MemberProfile,as:'Profile'}]}) .success(function(users){ if(users){ res.json(users); }else{ res.send('no users'); } }); }); // model.js module.exports = function(sequelize,sql) { return sequelize.define('Model', { /

Sequelize belongsToMany additional attributes in join table

最后都变了- 提交于 2019-12-06 15:05:22
I'm having problem with an additional attribute in the join table of the belongsToMany relation. In the set or add method this attribute is not being passed to mysql. I'm following the documentation pass as "through" the attribute within the set method, but it is not working. Would anyone know what could be wrong since following the documentation is not working? Note: The registration and update of the join is correct, only the additional attribute that is not being passed to the table. Functionality Model: export default function(sequelize, DataTypes) { const Functionality = sequelize.define(

Sequelize - How to get a list of nested table entries (Project -> Task through Milestones)?

自作多情 提交于 2019-12-06 14:37:34
Lets say I have the tables User, Project, Milestone, Task User.belongsToMany(Project, {through: ProjectUser}) Project.belongsToMany(User, {through: ProjectUser}) Project.hasMany(Milestone) Milestone.belongsTo(Project) Milestone.hasMany(Task) Task.belongsTo(Milestone) Now I can easily get all Milestones in a Project where a User belongs to: User.findAll({ include: [{ model: Project, include: [{ model: Milestone include: [ Task ] }] }] Now I would like to get the Tasks not inside the Milestones. Instead I would like to get the Tasks parallel to Milestones. Like this: User.findAll({ include: [{

Trying to create an instance and multiple related instances in a many to many relationship

五迷三道 提交于 2019-12-06 12:25:49
问题 I am attempting to create an instance and multiple related instances with a many to many relation using a junction table. While creating the multiple related instances, I need to add a value to a property on the junction table as well. I don't know if it is my lack of knowledge of sequelize or promises that is causing my problem. The code I am using is below. This code does add the items to the database, but I need to redirect after the operation has completed, which is not working. Basically

Sequelize 'hasMany' associated(model) count in attributes in query execution

自作多情 提交于 2019-12-06 11:32:08
问题 Sequelize version: 4.22.6, MySql version:5.7.8 I want to 'hasMany' associated(CompanyUser) count in attibutes(at place of _user_count_) in query execution /** * Company user associate with Company with belongsTo relation */ `CompanyUser.belongsTo(Company, { foreignKey: 'company_id', targetKey: 'id'});` /** * Company associate with Company user with hasMany relation */ `Company.hasMany(CompanyUser, { foreignKey: 'company_id', sourceKey: 'id'});` `return Company.findAll({ attributes: [ 'id',

findAll() from Sequelize doesn't get

本小妞迷上赌 提交于 2019-12-06 09:27:51
问题 I'm using Sequelize with MySQL. When I run this code: usuarioService.getAll = function () { Usuario.findAll().then(function (users) { //return users; console.dir(users); }); } Instead of get the user, I get: http://i.stack.imgur.com/uLhmN.png Help me, please! I'm going crazy! Thanks 回答1: Sequelize is returning an array of instance objects in users. An instance object has a number of convenience methods attached to it that allow you to act on it. If you want to get just the data with your

How to set extra attributes of through model on creation in SequelizeJS?

≡放荡痞女 提交于 2019-12-06 08:06:05
My models: Recipe (id, name) Ingredient (id, name) Recipe_Ingredient (recipeId, ingredientId, quantity) My associations: Recipe.belongsToMany(Ingredient, { through: Recipe_Ingredient }) Ingredient.belongsToMany(Recipe, { through: Recipe_Ingredient }) My problem: How can I create a Recipe with some Ingredients and the quantities attached to them? I tried: Recipe.create({ name: 'Pizza', ingredients:[ { name: 'mozarella', recipe_ingredients: { quantity: 5 } } ] }, { include:[Ingredient] }) Records are created for Recipe, Ingredient and the Recipe_Ingredient. The only problem is that the value of

Sequelize does not suport the MySQL 8 autentication protocol and I'm not getting how to change this protocol

天大地大妈咪最大 提交于 2019-12-06 08:04:46
I'm trying to migrate a db with Sequelize working with MySQL 8.0.15, but I'm not able to do that. I keep receiving this error message. Sequelize CLI [Node: 10.15.0, CLI: 5.4.0, ORM: 5.3.5] Loaded configuration file "config/config.json". Using environment "development". ERROR: Client does not support authentication protocol requested by server; consider upgrading MySQL client I've tried every single solution for this problem. The thing is when i try to change the MySQL root password the message i get is this one: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements