question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nitPICKS and incomplete implementation of model.$pick()

See original GitHub issue

First 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
koskimascommented, Dec 31, 2020

I’ll deprecate those methods and remove them in 3.0.

0reactions
JaneJeoncommented, Dec 31, 2020

@koskimas excellent, thanks for at least acknowledging this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common Mistakes - OpenGL Wiki - Khronos Group
If the OpenGL implementation does not support the particular format and precision you choose, the driver will internally convert it into ...
Read more >
Introduction to Software Testing Chapter 4 Input Space ...
Testing is fundamentally about choosing finite sets of values from the input domain ... Modeling can be based on requirements, not implementation.
Read more >
Part 15 - Contracting by Negotiation | Acquisition.GOV
15.508 Discovery of mistakes. 15.509 Forms. ... The objective of source selection is to select the proposal that represents the best value.
Read more >
Estimating Effects After Matching
Introduction. After assessing balance and deciding on a matching specification, it comes time to estimate the effect of the treatment in the matched...
Read more >
CI/CD pipelines explained: Everything you need to know
Planning to implement CI/CD? This comprehensive guide explores the stages of a CI/CD pipeline, its pros and cons, best practices and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found