Repository navigation
Fix doc for model.has return values - #1712
Merged
Merged
Conversation
ricardograca
self-requested a review
December 22, 2017 11:30
Member
|
I'm pretty sure the test didn't fail because of this change. |
ricardograca
approved these changes
Dec 22, 2017
ricardograca
left a comment
Member
There was a problem hiding this comment.
Looks good to me. We should really have a standard on how to format values, but not a big problem right now.
Author
|
@ricardogama thanks for the merge. I agree with you, the only failure in tests was during the installation of oracledb (link to Travis CI logs). It only fails against Node 7...and it doesn't look like it was just me; it started popping up 4 days ago on #1710. This is related to oracle/node-oracledb#811. I'll open an issue, as it looks like this won't be going away. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix doc for model.has return values
Introduction
model.has(attribute)returnstruewhen the attribute is set. If the attribute is not set, the function returnsfalse. The doc incorrectly states that the falsy returned value isnull.Motivation
It is generally considered best practice in JavaScript to use === instead of == when comparing values to ensure that automatic type conversion doesn't cause unintended consequences. While using
model.has(attribute), I was looked specifically for the function to returnnull(per docs) if the attribute was not set:As a result of the documentation error, I never get into the if-statement's body, because
model.has(attribute)never returnsnull. It always returns a boolean value as a result ofbookshelf/src/base/model.js
Line 325 in fd10651
Proposed solution
My solution is to update the documentation to reflect the current state of the source code.
model.has(attribute)always returns a boolean, which is correctly documented by this PR.Current PR Issues
None.
Alternatives considered
I also considered adding to the description statement (below), but found that the change to the
Returnssection was sufficient.bookshelf/src/base/model.js
Lines 319 to 320 in fd10651
If the function returns
truewhen an attribute is set, users quickly infer that it will returnfalseif the attribute is not set. The documentation doesn't need to repeat this information twice, once in theReturnssection, which this PR changes, and once in the description.