Skip to content

fix instance.set '1970-01-01' to null field - #6839

Merged
sushantdhiman merged 1 commit into
sequelize:v3from
neversun:v3
Nov 14, 2016
Merged

sushantdhiman merged 1 commit into
sequelize:v3from
neversun:v3

Conversation

@neversun

@neversun neversun commented Nov 11, 2016 •

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 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?
  • Have you added an entry under Future in the changelog?

Description of change

Before this change it is not possible to use instance.set('date', '1970-01-01') when:

  • model has allowNull: true
  • instance retrieved from database and thus date having null as value.

@mention-bot

Copy link
Copy Markdown

@neversun, thanks for your PR! By analyzing the history of the files in this pull request, we identified @limianwang, @gutobortolozzo and @sushantdhiman to be potential reviewers.

@codecov-io

codecov-io commented Nov 11, 2016 •

Copy link
Copy Markdown

Current coverage is 93.85% (diff: 100%)

Merging #6839 into v3 will increase coverage by <.01%

Powered by Codecov. Last update eff3852...2cc2165

@felixfbecker

Copy link
Copy Markdown
Contributor

We need this for master first, otherwise LGTM.

@joaobortolozzo

Copy link
Copy Markdown
Contributor

@neversun I would like to put two cents in your PR. I changed your code to

if (originalValue && !(originalValue instanceof Date)) {
  originalValue = new Date(originalValue);
}
if (originalValue && value.getTime() === originalValue.getTime()) {
 return this;
}

and tests looks to work just fine. What do you think about change your code to this shorter version?

Thank you

@felixfbecker

Copy link
Copy Markdown
Contributor

It is not shorter in terms of code branches. You are testing the same condition twice, while the PR only tests it once.

@sushantdhiman
sushantdhiman merged commit af3d9c1 into sequelize:v3 Nov 14, 2016
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.

6 participants