Python Eve - Query Embedded Data Relation
Asked Answered
U

2

9

I have the following resource defined:

item = {
    'wrapper': {
        'type': 'dict',
        'schema': {
            'element': {
                'type': 'objectid',
                'data_relation': {
                    'resource': 'code',
                    'field': '_id',
                    'embeddable': True,
                },
            },
        },
    },
}

When I try to query using the objectid, I get empty list.

http://127.0.0.1:5000/item?where={"wrapper.element":"5834987589b0dc353b72c27d"}

5834987589b0dc353b72c27d is the valid _id for the element.

If I move the data relation out of the embedded document I can query it as expected

Is there anyway to do this with an embedded data relation?

Up answered 23/11, 2016 at 16:11 Comment(5)
Are you sure you have an item inserted with 5834987589b0dc353b72c27d as value for wrapper.element?Careful
This is functionality still needed.Refer this link github.com/pyeve/eve-sqlalchemy/issues/100Vibrant
@bigbounty, the issue mentioned is not about the same thing. This one is just about filtering based on a objectid data_relation value, and the other is about embedding "sub-sub" documents as far as I can see.Careful
Yes, I do have an item with the ID that I am querying forUp
can we have the field in data relation set to some other field in referenced resorce? for example can I have 'id' instead of '_id'? Assuming that I have a field in the referenced table by that name.Evante
U
0

I had a problem where the _id was being stored as a string rather than an ObjectId(), this broke the query

Up answered 3/1, 2020 at 22:6 Comment(0)
C
1

I have just tested with eve==0.7.1 and it works as expected by filtering with ?where={"wrapper.element" : "<your_objectid>"}, as you said.

Careful answered 5/5, 2017 at 10:54 Comment(1)
Tested on 0.7.3 and it doesn't work for me, maybe it is some other part of my schema that is busting this. I will try a bare bones applicationUp
U
0

I had a problem where the _id was being stored as a string rather than an ObjectId(), this broke the query

Up answered 3/1, 2020 at 22:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.