Model field names truncated on multi-level includes
See original GitHub issueConsidering I have the following relationships setup:
db.Invoice.hasMany db.InvoiceLineItem
db.InvoiceLineItem.belongsTo db.Invoice
db.InvoiceLineItem.hasMany db.InvoiceLineItemAdjustment
db.InvoiceLineItemAdjustment.belongsTo db.InvoiceLineItem
db.InvoiceLineItemAdjustment.belongsTo db.LineItemAdjustmentType
db.LineItemAdjustmentType.hasMany db.InvoiceLineItemAdjustment
When I try to run the following query:
db.Invoice.findAll
where:
id: 1
is_active: true
include: [
model: db.InvoiceLineItem
include: [
model: db.InvoiceLineItemAdjustment
include: [
db.LineItemAdjustmentType
]
]
]
The returned result has truncated fields in each InvoiceLineItemAdjustment’s dataValue, with the following printed when logging each InvoiceLineItemAdjustment’s dataValue:
{
invoice_id: 1,
invoice_line_item_i: 1,
adjustment_amount: 4,
adjustment_percenta: null,
user_coupon_code_id: null,
is_active: true,
LineItemAdjustmentT: 'damage'
}
I have attempted aliasing the LineItemAdjustmentType using an ‘as’, with still no luck. When I try loading running the following query:
db.InvoiceLineItem.findAll
where:
invoice_id: 1
is_active: true
include: [
model: db.InvoiceLineItemAdjustment
include: [
db.LineItemAdjustmentType
]
]
The returned result for each InvoiceLineItemAdjustment’s dataValue is as expected:
{
invoice_id: 1,
invoice_line_item_item_id: 1,
adjustment_amount: 4,
adjustment_percentage: null,
user_coupon_code_id: null,
is_active: true,
LineItemAdjustmentType: {
dataValues: {
id: 3,
description: 'Damage',
lookup_key: 'damage',
is_active: true
}
}
}
I am not quite sure what is causing this issue, but it severely impacts the query performance for running complex queries with multi-level includes, because it essentially means I have to run the nested includes in separate queries. I’ve tested on the most recent version: 3.4.1. I’m wondering if anyone else has encountered this issue, and if there is a fix in the works for it. Thanks in advance!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:7
- Comments:17 (8 by maintainers)
@faceleg have a look in http://docs.sequelizejs.com/en/latest/api/model/#findalloptions-promisearrayinstance, in the options it mentions it (easiest is doing find on that page)
Thanks @simonv3 for the link, saved my life. All my column names once returned from Sequelize have been truncated to 5 characters (It was 4 levels deep in my GraphQL query) and this solved the problem and also allowed me to split the queries up a bit (my Cartesian product was getting out of hand