2016-07-22 8 views
0

Ich versuche, den Wert zu erhalten und postgres mich, dass diese Spalte nicht existiert. Ich bin nicht in der Lage, in irgendeiner Weise zu handeln.GETE Wert einer Beziehung in Sequelize js

"-Spalte Group.participant.id existiert nicht"

Beziehung:

User.belongsToMany(models.group, { as: 'Member', through: { model: models.participant, unique: false}, foreignKey: 'userId', constraints: false}); 

Group.belongsToMany(models.user, { as: 'Group', through: { model: models.participant, unique: false}, foreignKey: 'groupId', constraints: false }); 

Participant.belongsTo(models.user, { 
foreignKey: "userId", as: "Member" 
}); 

Participant.belongsTo(models.group, { 
foreignKey: "groupId", as: "Group" 
}); 

Query/Sequelizejs:

const User = app.db_connect.postgres.models.user; 

Group.findAll({ 
    include: [ 
    { model: User, 
     as: 'Group', 
     where: { 
      "participant.id": idUser 
     } 
     // attributes: ['name'] 
    } 
    ]}) 
    .then(result => res.json(result)) 
    .catch(error => { 
     res.status(412).json({msg: error.message}); 
    }); 

}); 

Abfrage generieren:

Executing (default): SELECT "group"."id", "group"."name", "group"."isMain", "group"."privacy", "group"."description", "group"."img", "group"."createdAt", "group"."updatedAt", "group"."destroyTime", "group"."categoryId", "Group"."id" AS "Group.id", "Group"."name" AS "Group.name", "Group"."birthday" AS "Group.birthday", "Group"."cpf" AS "Group.cpf", "Group"."email" AS "Group.email", "Group"."img" AS "Group.img", "Group"."status" AS "Group.status", "Group"."phone" AS "Group.phone", "Group"."cellPhone" AS "Group.cellPhone", "Group"."nickName" AS "Group.nickName", "Group"."password" AS "Group.password", "Group"."found" AS "Group.found", "Group"."createdAt" AS "Group.createdAt", "Group"."updatedAt" AS "Group.updatedAt", "Group"."destroyTime" AS "Group.destroyTime", "Group.participant"."id" AS "Group.participant.id", "Group.participant"."function" AS "Group.participant.function", "Group.participant"."createdAt" AS "Group.participant.createdAt", "Group.participant"."updatedAt" AS "Group.participant.updatedAt", "Group.participant"."groupId" AS "Group.participant.groupId", "Group.participant"."userId" AS "Group.participant.userId" FROM "groups" AS "group" INNER JOIN ("participants" AS "Group.participant" INNER JOIN "users" AS "Group" ON "Group"."id" = "Group.participant"."userId") ON "group"."id" = "Group.participant"."groupId" AND ("Group"."destroyTime" IS NULL AND "Group"."participant.id" = 1) WHERE "group"."destroyTime" IS NULL; 

Returns ohne Wo: Pastebin

Antwort

0

Verwendung nur id in where, weil in Abschnitt umfassen Sie mit Spalten von spezifischen Modell arbeiten

Group.findAll({ 
    include: [{ model: User, as: 'Group', 
    where: { 
     "id": idUser 
    } 
    }]}) 
+0

Nein, Wenn ich versuche, durch „Funktion“ zu erhalten erscheint Error. –

Verwandte Themen