Продолжение неизвестного столбца '' в 'по предложению'
Уважаемые у меня есть приведенный ниже код, и он работает нормально, но у меня возникла проблема, и я попытался включить таблицу изображений
Уже существует связь между порядком и изображениями, но я не знаю, почему он 'показывает ошибку ниже
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']
}
]
})
я проверил отношения внутри каждой модели, и это нормально, не проблема
Модель заказа:
Order.hasMany(models.images, {
foreignKey: 'imagebleId',
scope: {
imageable: 'Order'
}
});
Изображения модели:
images.belongsTo(models.Order, { foreignKey: "imagebleId" });
1 ответ
Я попробовал решение @Ellebkey (опубликовано как комментарий выше)
Попробуйте добавить
as
атрибут наimages
определение модельной ассоциации и включение также.
использование (как) работает как шарм.