nitPICKS and incomplete implementation of model.$pick()
See original GitHub issueFirst of all, sorry (not sorry), but I had to get that pun in there.
While maintaining my new version of objection-authorize, I came across a small issue that others somehow surprisingly didn’t point out before:
The internal implementation of pick
does NOT support dot notations (due to using Object.keys()
):
https://github.com/Vincit/objection.js/blob/412bb77b9cf69496e477c38fc10bca679ceca461/lib/model/modelFilter.js#L77
This means that if you have a model with a JSON field, and you’d like to selectively “pick out” a subfield (e.g. a.b
from a model represented by object {a: {b: 'foo'}}
, it will not properly recognize that subfield (Object.keys({a: {b: 'foo'}})
is a
, after all).
So to properly implement “picking” subfields, you’d either need to re-implement JSON dotpath, or, just use lodash.omit
and lodash.pick
. Either way, if you’re not going to implement this change, you really should note on the docs that it doesn’t support dot notation and nested fields.
As for the nitPICK… in line 84 of that file I noticed that you were just iterating over the pick
array to check rather than using Array.prototype.includes()
or better yet, producing a set from that array and checking membership for that sweet, sweet O(1) lookup time.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
I’ll deprecate those methods and remove them in 3.0.
@koskimas excellent, thanks for at least acknowledging this!