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

add class method "increment" #7394

Merged
merged 2 commits into from
Jun 8, 2017
Merged

add class method "increment" #7394

merged 2 commits into from
Jun 8, 2017

Conversation

hieven
Copy link
Contributor

@hieven hieven commented Mar 18, 2017

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 your issue contain a link to existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Have you added an entry under Future in the changelog?

NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.

Description of change

I move the instance method increment code to be class method increment.
The original instance method increment will simply add this.where() to options.where and then call this.constructor.increment().

This is the very first open source contribution I do.
Please give me any advices to improve this PR :-)

I will write document and changelog if this PR is acceptable

close #6359

@codecov-io
Copy link

codecov-io commented Mar 18, 2017

Codecov Report

Merging #7394 into master will decrease coverage by <.01%.
The diff coverage is 97.77%.

@hieven
Copy link
Contributor Author

hieven commented Mar 18, 2017

the test fails in a strange line of code.
it would be great if someone could help me figure this out.
It has taken me for a few hours but got nothing. 😓

Copy link
Member

@janmeier janmeier left a comment

Choose a reason for hiding this comment

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

Sorry for leaving this for so long @hieven - I'll address the comments myself and push to your branch :)


options.type = QueryTypes.UPDATE;
options.instance = instance;
Copy link
Member

Choose a reason for hiding this comment

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

This line is what makes returning: true work - It shouldn't be removed :)

stub.restore();
});

it('should allow increments even if options are not given', function () {
Copy link
Member

Choose a reason for hiding this comment

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

We should require where to be defined, like we do for update, so users don't accidentally update all rows in the database

lib/model.js Outdated
}

if (!options.increment) {
return this.sequelize.getQueryInterface().decrement(this, this.getTableName(options), values, where, options).then(affectedRows => {
Copy link
Member

Choose a reason for hiding this comment

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

The then handlers are duplicated here

@janmeier janmeier self-assigned this Apr 12, 2017
@hieven
Copy link
Contributor Author

hieven commented Apr 13, 2017

Thanks for the quick help and the test finally passes!

I'd like to receive more suggestions for improving this PR since this is the very first contribution I make for open source. :-)

@janmeier
Copy link
Member

janmeier commented Jun 8, 2017

@hieven I don't have any other comments I think, code style looks good, and I like your thoroughness in testing :)

hieven and others added 2 commits June 8, 2017 22:21
Basically moving code from instance method `increment` to class method `increment`.

close #6359
@janmeier janmeier merged commit 99d87df into sequelize:master Jun 8, 2017
@hieven
Copy link
Contributor Author

hieven commented Jun 9, 2017

@janmeier
Thank you for the comment. :-)

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.

[Suggestion] Increment fields using Model.
3 participants