亲爱的我有下面的代码,它工作正常,但有问题,我试图包括图像表
订单和图片之间已经存在关系,但我不知道为什么它显示以下错误
c:\python>python c:\python\scripts\pip install formulas
代码下方:
c:\python\scripts> c:\python\python pip install formulas
我检查了每个模型内的关系,这没问题
订单模型:
Unhandled rejection SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'images.imageable' in 'on clause'
图片模型:
models.Order.findOne({
where : {
id : req.params.orderId
},
attributes: ['id','comment','rating','orderDescription','userLat','userLng','orderStatus','providerId','isUsingBalance','userId','serviceId','createdAt','updatedAt','ticketNumber',
'orderScheduledDate', 'promoId','paymentMethodId',
[sequelize.Sequelize.fn('date_format', sequelize.Sequelize.col('orderScheduledDate'), '%Y-%m-%D %h:%i'),'orderScheduledDateToEdit']
],
include: [
{
model : models.Comment,
include: [
{
model : models.User,
attributes: ['firstName','lastName','id']
}
]
},
{
model: models.Provider,
attributes: ['id','userId'],
include:
[
{
model : models.User,
attributes: ['id','firstName','lastName','phoneNumber']
},
{
model : models.ProviderLocation,
attributes: ['lat','lng','providerId']
},
{
model : models.PaymentMethod,
through: {
where: {status: "ACTIVE"}
}
}
]
},
{
model : models.User,
attributes: ['id','firstName','lastName','phoneNumber','status'],
include : [
{
model: models.Balance,
attributes: ['balance']
}
]
},
{
model : models.notified_providers ,
attributes: ['orderId','providerBroadcastedId','distance','duration','status','rank_score','rate_score','distance_score','nationality_score','total_score'],
include: [
{
model: models.Provider,
attributes: ['id'],
include: [
{
model: models.User,
attributes: ['id','firstName','lastName','phoneNumber','status','rate','rankId']
},
{
model : models.PaymentMethod,
through: {
where: {status: "ACTIVE"}
}
}
]
}
]
},
{
model : models.rate,
attributes: ['rate']
},
{
model : models.Service,
attributes: ['serviceType']
},
{
model : models.Promotion,
attributes: ['code','conditions']
},
{
model : models.PaymentMethod,
attributes: ['name','image']
},
{
model: models.images,
attributes: ['imageble','image','imagebleId']
}
]
})
答案 0 :(得分:0)
我尝试了@Ellebkey解决方案(在上面的评论中发布)
尝试在
as
模型关联定义和包含上添加images
属性。
使用(AS)很有魅力。