admin管理员组文章数量:1302270
I have this code that queries all the data under my feedback model
const result = await models.Feedback.findOne({
include: [{
association: models.Feedback.Point,
order: [["date_saved", "DESC"]],
// where: { version_id: { [Op.not]: null } },
include: [{
association: models.Point.Creator
}, {
association: models.Point.User,
}, {
association: models.Point.Comment,
}]
}, {
association: models.Feedback.Project,
where: { subscription_id: currentUser.subscription_id }
}, {
association: models.Feedback.User,
include: [{
association: models.ProjectTeam.User
}]
}],
where: { id },
});
console.log(result.get({plain:true})'
It gives me an error result.get is not a function
. I don't know why I can't use the get function. But from my other query, i can use the get function. I don't know why this code give me an error.
EDIT:
The value of the result is
ep_tblfeedback {
dataValues:
{ id: 239,
proj_id: 20006,
title: 'sample',
status: 'Open',
date_saved: 2019-08-07T09:41:16.000Z,
title_trans: null,
Points: [ [ep_tblpoint] ],
Project:
ep_tblproject {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false },
Users:
[ [ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team] ] },
_previousDataValues:
{ id: 239,
proj_id: 20006,
title: 'sample',
status: 'Open',
date_saved: 2019-08-07T09:41:16.000Z,
title_trans: null,
Points: [ [ep_tblpoint] ],
Project:
ep_tblproject {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false },
Users:
[ [ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team] ] },
_changed: {},
_modelOptions:
{ timestamps: false,
validate: {},
freezeTableName: false,
underscored: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: { id: 239 },
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: { plural: 'ep_tblfeedbacks', singular: 'ep_tblfeedback' },
omitNull: false,
tableName: 'ep_tblfeedback',
sequelize:
Sequelize {
options: [Object],
config: [Object],
dialect: [MysqlDialect],
queryInterface: [QueryInterface],
models: [Object],
modelManager: [ModelManager],
connectionManager: [ConnectionManager],
importCache: [Object] },
hooks: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
include: [ [Object], [Object], [Object] ],
includeNames: [ 'Points', 'Project', 'Users' ],
includeMap: { Points: [Object], Project: [Object], Users: [Object] },
includeValidated: true,
attributes:
[ 'id', 'proj_id', 'title', 'status', 'date_saved', 'title_trans' ],
raw: true },
isNewRecord: false,
Points:
[ ep_tblpoint {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
Creator: [ep_tblusers],
Users: [Array],
ments: [Array] } ],
Project:
ep_tblproject {
dataValues:
{ id: 20006,
proj_name: 'exactplace',
client_id: 291,
proj_nr: 'ep-01',
subscription_id: 1000,
status: 'Open' },
_previousDataValues:
{ id: 20006,
proj_name: 'exactplace',
client_id: 291,
proj_nr: 'ep-01',
subscription_id: 1000,
status: 'Open' },
_changed: {},
_modelOptions:
{ timestamps: false,
validate: {},
freezeTableName: false,
underscored: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: [Object],
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: [Object],
omitNull: false,
tableName: 'ep_tblproject',
sequelize: [Sequelize],
hooks: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
include: undefined,
includeNames: undefined,
includeMap: undefined,
includeValidated: true,
raw: true,
attributes: undefined },
isNewRecord: false },
Users:
[ ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] } ] }
If I use result.dataValues or result.get('field') works. But result.get({plain: true}) doesn't work. I want to use the latter because that's what I declared from my GraphQLObjectTypes and it would be a too much of work if i'll change all its functions.
I want to know what caused this error, to get it to work.
EDIT (2): I discovered that from my front end, Apollo React causes the error. I don't know what is the logic to the error, but rearranging the fields does the trick.
export const FEEDBACK_QUERY = (id) => gql`
{
feedback (id: ${id}) {
id
title
proj_id
proj_name
clientname
date_saved
versions {
id
version_name
__typename @include(if: false)
}
points {
id
point_nr
version_name
time_approve
time_estimate
priority
team {
id
name
project_role
__typename @include(if: false)
}
instructions
inst_engtrans
status
deadline
creator
ments {
id
user_id
ments
date_mented
__typename @include(if: false)
}
ack
date
__typename @include(if: false)
}
team {
id
name
email
project_role
__typename @include(if: false)
}
__typename @include(if: false)
}
}
`;
Still don't know why rearranging the fields fixes it.
I have this code that queries all the data under my feedback model
const result = await models.Feedback.findOne({
include: [{
association: models.Feedback.Point,
order: [["date_saved", "DESC"]],
// where: { version_id: { [Op.not]: null } },
include: [{
association: models.Point.Creator
}, {
association: models.Point.User,
}, {
association: models.Point.Comment,
}]
}, {
association: models.Feedback.Project,
where: { subscription_id: currentUser.subscription_id }
}, {
association: models.Feedback.User,
include: [{
association: models.ProjectTeam.User
}]
}],
where: { id },
});
console.log(result.get({plain:true})'
It gives me an error result.get is not a function
. I don't know why I can't use the get function. But from my other query, i can use the get function. I don't know why this code give me an error.
EDIT:
The value of the result is
ep_tblfeedback {
dataValues:
{ id: 239,
proj_id: 20006,
title: 'sample',
status: 'Open',
date_saved: 2019-08-07T09:41:16.000Z,
title_trans: null,
Points: [ [ep_tblpoint] ],
Project:
ep_tblproject {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false },
Users:
[ [ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team] ] },
_previousDataValues:
{ id: 239,
proj_id: 20006,
title: 'sample',
status: 'Open',
date_saved: 2019-08-07T09:41:16.000Z,
title_trans: null,
Points: [ [ep_tblpoint] ],
Project:
ep_tblproject {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false },
Users:
[ [ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team],
[ep_tblproject_team] ] },
_changed: {},
_modelOptions:
{ timestamps: false,
validate: {},
freezeTableName: false,
underscored: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: { id: 239 },
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: { plural: 'ep_tblfeedbacks', singular: 'ep_tblfeedback' },
omitNull: false,
tableName: 'ep_tblfeedback',
sequelize:
Sequelize {
options: [Object],
config: [Object],
dialect: [MysqlDialect],
queryInterface: [QueryInterface],
models: [Object],
modelManager: [ModelManager],
connectionManager: [ConnectionManager],
importCache: [Object] },
hooks: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
include: [ [Object], [Object], [Object] ],
includeNames: [ 'Points', 'Project', 'Users' ],
includeMap: { Points: [Object], Project: [Object], Users: [Object] },
includeValidated: true,
attributes:
[ 'id', 'proj_id', 'title', 'status', 'date_saved', 'title_trans' ],
raw: true },
isNewRecord: false,
Points:
[ ep_tblpoint {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
Creator: [ep_tblusers],
Users: [Array],
ments: [Array] } ],
Project:
ep_tblproject {
dataValues:
{ id: 20006,
proj_name: 'exactplace',
client_id: 291,
proj_nr: 'ep-01',
subscription_id: 1000,
status: 'Open' },
_previousDataValues:
{ id: 20006,
proj_name: 'exactplace',
client_id: 291,
proj_nr: 'ep-01',
subscription_id: 1000,
status: 'Open' },
_changed: {},
_modelOptions:
{ timestamps: false,
validate: {},
freezeTableName: false,
underscored: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: [Object],
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: [Object],
omitNull: false,
tableName: 'ep_tblproject',
sequelize: [Sequelize],
hooks: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
include: undefined,
includeNames: undefined,
includeMap: undefined,
includeValidated: true,
raw: true,
attributes: undefined },
isNewRecord: false },
Users:
[ ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] },
ep_tblproject_team {
dataValues: [Object],
_previousDataValues: [Object],
_changed: {},
_modelOptions: [Object],
_options: [Object],
isNewRecord: false,
ep_tbluser: [ep_tblusers] } ] }
If I use result.dataValues or result.get('field') works. But result.get({plain: true}) doesn't work. I want to use the latter because that's what I declared from my GraphQLObjectTypes and it would be a too much of work if i'll change all its functions.
I want to know what caused this error, to get it to work.
EDIT (2): I discovered that from my front end, Apollo React causes the error. I don't know what is the logic to the error, but rearranging the fields does the trick.
export const FEEDBACK_QUERY = (id) => gql`
{
feedback (id: ${id}) {
id
title
proj_id
proj_name
clientname
date_saved
versions {
id
version_name
__typename @include(if: false)
}
points {
id
point_nr
version_name
time_approve
time_estimate
priority
team {
id
name
project_role
__typename @include(if: false)
}
instructions
inst_engtrans
status
deadline
creator
ments {
id
user_id
ments
date_mented
__typename @include(if: false)
}
ack
date
__typename @include(if: false)
}
team {
id
name
email
project_role
__typename @include(if: false)
}
__typename @include(if: false)
}
}
`;
Still don't know why rearranging the fields fixes it.
Share edited Aug 14, 2019 at 1:48 Techuila asked Aug 13, 2019 at 16:38 TechuilaTechuila 1,2878 silver badges12 bronze badges2 Answers
Reset to default 10Another way of doing this is raw:true, nest:true
:
const result = await models.Feedback.findOne({
include: [
...
],
where: {
...
},
raw : true ,
nest : true
});
set raw parameter as true or false. without this parameters some queries may be get error. in my app I set the {raw: true} in setting section. I set to true or false when trying to join models
本文标签: javascriptSequelize instanceget is not a functionStack Overflow
版权声明:本文标题:javascript - Sequelize: instance.get is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741692785a2392829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论