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 dougs-compta:fixAssociationScopeAssignation branch from 14f7630 to 92ecf72 Apr 12, 2018
Verdier added a commit to dougs-compta/sequelize that referenced this pull request Apr 12, 2018
@Verdier Verdier force-pushed the dougs-compta:fixAssociationScopeAssignation branch from 92ecf72 to 0d069bf Apr 12, 2018
@codecov
Copy link

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

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;

This comment has been minimized.

@sushantdhiman

sushantdhiman Apr 13, 2018
Contributor

No need for self with arrow functions

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

This comment has been minimized.

@sushantdhiman

sushantdhiman Apr 13, 2018
Contributor

No bind

@Verdier Verdier force-pushed the dougs-compta:fixAssociationScopeAssignation branch from 0d069bf to 5b5f6b6 Apr 13, 2018
@Verdier
Copy link
Contributor Author

@Verdier Verdier commented Apr 13, 2018

@sunshinewyin done ^^

@sushantdhiman sushantdhiman merged commit 3b12097 into sequelize:master Apr 13, 2018
4 checks passed
4 checks passed
codecov/patch 100% of diff hit (target 95.93%)
Details
codecov/project Absolute coverage decreased by -<.01% but relative coverage increased by +4.06% compared to 1b295c0
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
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
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants