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: previousChanges should check instance is new record or not while specific attributes' values were undefined #276

Merged
merged 3 commits into from
Feb 21, 2022

Conversation

JimmyDaddy
Copy link
Collaborator

// title: Untitled, authorId: undefined
const post = new Post({ title: 'Untitled' });
assert.deepEqual(post.previousChanges('title'), {});
assert.deepEqual(post.previousChanges('authorId'), {});
post.title = 'MHW';
// authorId was undefined
post.authorId = 100;
await post.save();
// post is not a new record now
assert.deepEqual(post.previousChanges('authorId'), { authorId: [ null, 100 ] });

@JimmyDaddy JimmyDaddy changed the title fix: previousChanges should check instance is new record or not while specific attributes' value were undefined fix: previousChanges should check instance is new record or not while specific attributes' values were undefined Feb 19, 2022
@codecov-commenter
Copy link

codecov-commenter commented Feb 19, 2022

Codecov Report

Merging #276 (6c48617) into master (8d98cc0) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #276   +/-   ##
=======================================
  Coverage   97.47%   97.47%           
=======================================
  Files          44       44           
  Lines        3204     3204           
=======================================
  Hits         3123     3123           
  Misses         81       81           
Impacted Files Coverage Δ
src/bone.js 97.98% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d98cc0...6c48617. Read the comment docs.

src/bone.js Outdated
@@ -371,15 +371,15 @@ class Bone {
*/
previousChanges(name) {
if (name != null) {
if (this.#rawUnset.has(name) || this.#rawPrevious[name] === undefined || !this.hasAttribute(name)) return {};
if (this.#rawUnset.has(name) || (this.#rawPrevious[name] === undefined && this.isNewRecord) || !this.hasAttribute(name)) return {};
Copy link
Owner

@cyjake cyjake Feb 21, 2022

Choose a reason for hiding this comment

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

It looks like this.isNewRecord covers this.#rawPrevious[name] === undefined already, can we give it a try?

btw, this line is a bit too much now, I believe a multiple line if block is necessary once the column width exceeds some threshold like 90 or 120

@cyjake cyjake merged commit 9b31605 into master Feb 21, 2022
@cyjake cyjake deleted the fix/previous_changes_is_new_record branch February 21, 2022 03:46
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.

3 participants