You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with a codebase that is using Objection.js to create database models from a Postgres DB. The model in question has a property represented in the DB as a JSONB not null data type, so we anticipate that when we run a query returning a row where this column is an empty JSON object, we'll get something like model.jsonColumn = {}.
I noticed that when I try to either run a Keys.filter(model, ['!jsonColumn']) blacklist or do not include jsonColumn in my whitelist, the jsonColumn value still displays with the empty object. I've played around with manipulating the properties of our model, and I've noticed that the filtering does work when I wrap the JSON.stringify method around the column, i.e. model.jsonColumn = JSON.stringify(model.jsonColumn).
I'm wondering if it would make sense to update the Keys.filter to handle properties whose values are empty objects as a quality-of-life improvement. Would love to hear your thoughts, and thanks for this library!
The text was updated successfully, but these errors were encountered:
@bjamba Thanks for raising the question. I actually spent quite some time thinking on the best way to deal with empty objects when I wrote the filter utility.
What behavior would you see happening for the following example?
I'm currently seeing the result as { a: {} }. I think if I were to think about what I would like to see in that instance, I'd think I'd like to see { b: {} }, since if we're nesting into properties.
I guess to put it another way, the way I imagine the filters could work is so that if you are explicitly filtering out a parent key, it should filter out anything that's a child of it. But if I'm filtering a child key that would effectively render the parent key to be an empty object, we preserve the object.
Hi, circling back on this to ask if there had been any additional thoughts on solving this issue or if there was more clarification on my end that was needed. Thanks!
@bjamba Sorry for not getting back to you earlier. What you are saying makes total sense and I'll provide a fix within 10 days. If you wish to make a PR yourself, that's even better!
I'm working with a codebase that is using Objection.js to create database models from a Postgres DB. The model in question has a property represented in the DB as a
JSONB not null
data type, so we anticipate that when we run a query returning a row where this column is an empty JSON object, we'll get something likemodel.jsonColumn = {}
.I noticed that when I try to either run a
Keys.filter(model, ['!jsonColumn'])
blacklist or do not includejsonColumn
in my whitelist, thejsonColumn
value still displays with the empty object. I've played around with manipulating the properties of our model, and I've noticed that the filtering does work when I wrap theJSON.stringify
method around the column, i.e.model.jsonColumn = JSON.stringify(model.jsonColumn)
.I'm wondering if it would make sense to update the
Keys.filter
to handle properties whose values are empty objects as a quality-of-life improvement. Would love to hear your thoughts, and thanks for this library!The text was updated successfully, but these errors were encountered: