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

fix(scope): do not assign scope on eagerly loaded associations #9292

Merged

Conversation

Verdier
Copy link
Contributor

@Verdier Verdier commented Apr 12, 2018

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Fix an issue introduced by #9127 when eager loading association with complex scope, such as:

Post.hasMany(this.Comment, {
    foreignKey: 'commentable_id',
    as: 'coloredComments',
    scope: {
        commentable: 'post',
        type: { [Op.in]: ['blue', 'green'] }
    },
    constraints: false
});

When assigning the scope to the instance in _setInclude, the instance's property type became comment.type === { [Op.in]: ['blue', 'green'] }.

This fix move the assignation of the association scope only on creation.

@Verdier Verdier force-pushed the fixAssociationScopeAssignation branch from 14f7630 to 92ecf72 Compare April 12, 2018 11:06
Verdier added a commit to dougs-compta/sequelize that referenced this pull request Apr 12, 2018
@Verdier Verdier force-pushed the fixAssociationScopeAssignation branch from 92ecf72 to 0d069bf Compare April 12, 2018 12:47
@codecov
Copy link

codecov bot commented Apr 12, 2018

Codecov Report

Merging #9292 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Verdier added a commit to dougs-compta/sequelize that referenced this pull request Apr 12, 2018
Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a few suggestions for tests

@@ -287,6 +298,41 @@ describe(Support.getTestDialectTeaser('associations'), () => {
expect(comment.get('commentable')).to.equal('post');
});
});
it('should include associations with operator scope values', function() {
const self = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for self with arrow functions

type: 'green'
})
);
}).bind(this).spread(function(post, commentA, commentB, commentC) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No bind

@Verdier Verdier force-pushed the fixAssociationScopeAssignation branch from 0d069bf to 5b5f6b6 Compare April 13, 2018 08:24
@Verdier
Copy link
Contributor Author

Verdier commented Apr 13, 2018

@sunshinewyin done ^^

@sushantdhiman sushantdhiman merged commit 3b12097 into sequelize:master Apr 13, 2018
Verdier added a commit to dougs-compta/sequelize that referenced this pull request Nov 20, 2018
Verdier added a commit to dougs-compta/sequelize that referenced this pull request Jul 16, 2019
fix(model): fix a bug with findSeparate

docs(packages): Bump version

fix(scope): backport sequelize#9292

fix(core): Fix nested savepoints

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

Successfully merging this pull request may close these issues.

2 participants