Skip to content

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

Merged
sushantdhiman merged 1 commit into
sequelize:masterfrom
dougs-compta:fixAssociationScopeAssignation
Apr 13, 2018
Merged

fix(scope): do not assign scope on eagerly loaded associations#9292
sushantdhiman merged 1 commit into
sequelize:masterfrom
dougs-compta:fixAssociationScopeAssignation

Conversation

@verdier

@verdier verdier commented Apr 12, 2018

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Apr 12, 2018

Copy link
Copy Markdown

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

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

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

});
});
it('should include associations with operator scope values', function() {
const self = this;

Copy link
Copy Markdown
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
Copy Markdown
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

verdier commented Apr 13, 2018

Copy link
Copy Markdown
Contributor Author

@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