dmfay / massive-js

A data mapper for Node.js and PostgreSQL.
2.49k stars 158 forks source link

JSON object traversal does not work for complex objects #594

Closed ghost closed 6 years ago

ghost commented 6 years ago

I have a table with documents which have next body structure

{
    ...
    entity: {
        id: 1,
        name: 'entity'
    }
    ...
}

I want to query these documents by where in condition. So I try to call

db.table.findDoc({
    'entity.id': [1, 2, 3]
})

As result SQL query become like this

SELECT * FROM "entities" WHERE ("body" ->> 'entity') IN (1, 2, 3)

but it should be

SELECT * FROM "entities" WHERE ("body" -> 'entity' ->> 'id') IN (1, 2, 3)

Node.js: 8.11.1 Massive: 4.7.2

dmfay commented 6 years ago

Thanks for the reports! I didn't know if this was going to be possible at first with all the special handling document criteria already get but it seems to have worked out okay. Update to 4.8.2 next chance you get.