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

Don't work when filtering on a json sub-property and using $in #113

Open
mdartic opened this issue Sep 7, 2020 · 4 comments
Open

Don't work when filtering on a json sub-property and using $in #113

mdartic opened this issue Sep 7, 2020 · 4 comments

Comments

@mdartic
Copy link

mdartic commented Sep 7, 2020

I'm trying to filter rows from a table where a filter is set on a sub-property of a jsonb field.

I have a model / service named row, where I have a data property that is a jsonb. In this data, I have some other fields, like this :

{
  id: 1,
  data: {
    mySubProperty: 10,
    myOtherSubProperty: {
      lastField: 20
    }
  }
}

I would like to filter on the lastField for example, or the mySubProperty.

I try a query like that :

{
  data : {
    mySubProperty: 10
  }
}

This is working.

But my goal is to use the $in.

So, I try this one :

{
  data : {
    mySubProperty: {
      $in: [10, 20]
    }
  }
}

This is not working.
By observing the debug logs, I can see the package take in account only the "last" property, that is to say mySubProperty, and don't think about the data field, which is specified in the row jsonSchema model as an object.

Same for the lastField property.

I've tried to update the code, and I think I find a way to update the code for making this work, and to make the objectify function able to remember the root field was an object one, so a jsonb field.

But, maybe there is a simple way that I didn't found.

If not, could you check the code here : mdartic@b5768cf

And tell me if it's a good way / idea ?
If it's ok, I could propose a PR ? (and I would like to add some tests, but don't know how to make them reliable)

@dekelev
Copy link
Member

dekelev commented Sep 18, 2020

Thanks @mdartic, it looks good. Please open a PR with few tests. Testing only the $in method in a JSON object will suffice as long as you do not introduce breaking-changes and do take your time to think on more use cases and if this PR will address them too.

@mdartic
Copy link
Author

mdartic commented Oct 17, 2020

I'm trying to add some tests, in 6.0.0, and that seems to be ok.

But in fact, when I use it in my project, with the 6.0.0, problem is still the same.

I expect the tests are not "ok", because we don't use under the hood a real PostgreSQL database.

I'm going to try to make the test working on a PgSQL DB, do you think it's a good idea ? I'm thinking it's the only way to be sure my code is really working as I would expect.

@dekelev
Copy link
Member

dekelev commented Oct 17, 2020 via email

@philipimperato
Copy link

Hmm, well json fields are not a functional feature if you can't query on it.

I would love to have known this before spending time moving stuff to json fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants