Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested included tables are not returned if their parent's attributes field is "[]" #12888

Open
2 of 7 tasks
ivanpera opened this issue Dec 4, 2020 · 8 comments
Open
2 of 7 tasks

Comments

@ivanpera
Copy link

ivanpera commented Dec 4, 2020

Issue Description

The database is structured as following:

Tables:

  • Users (model name: UserModel)
  • Users_As (model name: AModel)
  • As_Ds (model name: DModel)

Associations:

  • UserModel.hasOne(AModel)
  • AModel.hasOne(DModel)

When calling UserModel.findAll() including both AModel and DModel, but specifiyng AModel attributes as "[]", no instance of DModel is returned.
When adding a field to the attributes of AModel, DModel is returned correctly.

What are you doing?

Here is the link to the SSCCE for this issue: LINK-HERE https://github.com/ivanpera/sequelize_issue

What do you expect to happen?

Given the following query

let res = await UserModel.findAll({
    model: UserModel,
    attributes : [],
    include: [{
      model : AModel,
      attributes : [],
      include : [{
        model : DModel,
        attributes: {all : true}
      }]
    }]
  })

I expect res["a"]["d"] to be defined
NOTE: "a" and "d" are the names of the tables in associations, as defined in their init functions

Environment

  • Sequelize version: 6.3.5
  • Node.js version: 12.16.3
  • Operating System: Windows 10
  • TypeScript version (not Typescript relate, I believe, but I'm using it): 4.1.2

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@jdgriffith
Copy link

jdgriffith commented Jul 24, 2021

I am experiencing the same issue. I have a deeply nested model with a specific attribute needing to be returned and sequelize is not populating the models and respective children (nested) after the query is run. What's odd is I am seeing the correct query hit the database, so seems like an object mapper issue after the data is returned from the db.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Oct 28, 2021
@ivanpera
Copy link
Author

Still an issue, as far is I know (I've not been using sequelize for a long time).
@jdgriffith As stated in the description, to work around the issue you can include some useless fields in tables like "As" and just filter them out manually later

@jdgriffith
Copy link

Thanks, @ivanpera. I looked at their object mapper and it's some pretty gnarly looking code. Our team has been able to get around this by including the primary key id in the parent model.

@github-actions github-actions bot removed the stale label Oct 29, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 6, 2021
@WikiRik WikiRik removed the stale label Nov 15, 2021
@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@jdgriffith
Copy link

We are still experiencing this issue in our applications. This should not be closed (unless it's fixed in another PR/issue) and is a very serious issue for an object mapper.

@WikiRik WikiRik added type: bug and removed stale labels Dec 16, 2021
@WikiRik WikiRik reopened this Dec 16, 2021
@jdgriffith
Copy link

Thanks for re-opening!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants