question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model field names truncated on multi-level includes

See original GitHub issue

Considering 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:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

10reactions
simonv3commented, Aug 2, 2016

@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)

7reactions
moseleyicommented, Apr 19, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Properties' name being truncated, sequelize bug?
The field names are correctly set in the tables ( furthermore the same PersonAnswers table is used for the Person's answers which are...
Read more >
Field names are truncated to ten characters in ArcMap and ...
Field names are truncated to ten characters in ArcMap and ArcGIS Pro when exporting shapefiles from ArcGIS Online. Description.
Read more >
3.7.3 Censored, truncated and rounded data - Stef van Buuren
Truncated data are less informative than censored data, and consequently truncation has a larger potential to distort the inferences of interest. The usual ......
Read more >
A Tutorial on Multilevel Survival Analysis: Methods, Models ...
The case study consists of a large cohort of patients hospitalised with acute myocardial infarction (AMI or heart attack), who are nested within ......
Read more >
PHP & SQL Server - field names truncated - Stack Overflow
Apparently the problem is with ODBC. There's a bug in PHP where column names are truncated at 31 characters, and the only way...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found