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

col references in scopes break when the model is included #13889

Open
3 of 8 tasks
Fardenz opened this issue Jan 3, 2022 · 3 comments
Open
3 of 8 tasks

col references in scopes break when the model is included #13889

Fardenz opened this issue Jan 3, 2022 · 3 comments

Comments

@Fardenz
Copy link

Fardenz commented Jan 3, 2022

Issue Creation Checklist

Bug Description

SSCCE

Here is the link to the SSCCE for this issue: LINK-HERE

Alternative Link in my cloned repository

What do you expect to happen?

When having a sequelize scope and querying some entity, the include works as expected.

But when including that entity in another entity query, it fails because the reference to the first entity is not correct.

I expect this code to not throw an error and the check from line 72 to work.

Screenshot_20220103_165739

Environment

  • Sequelize version: 6.12.4
  • Node.js version: v14.17.0

Bug Report 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.
@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. 🙂

@github-actions github-actions bot added the stale label Jan 18, 2022
@Fardenz
Copy link
Author

Fardenz commented Jan 18, 2022

This is still an issue for me. In this SSCCE you can see how just by importing another entity the query is malformed and crashes the program.

@WikiRik WikiRik added type: bug and removed stale labels Jan 18, 2022
@ephys ephys changed the title dialect specific column identifiers reference error col references in scopes break when the model is included Jan 22, 2022
@ephys
Copy link
Member

ephys commented Jan 22, 2022

In your SSCCE, I think your on clause in your default scope should have been:

on: {
  'name2': { [Op.col]: 'foo.name2' }
}

otherwise you'll end up with bar.name2 = bar.name2


As for the actual issue. I think we could fix this in Model._validateIncludedElement + Model._injectScope: References to the scope owner's table could be transformed:

on: {
  'name2': { [Op.col]: 'foo.name2' }
}

would becomes

on: {
  'name2': { [Op.col]: 'bar.foo.name2' }
}

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