kaleidos / grails-postgresql-extensions

Grails plugin to use postgresql native elements such as arrays, hstores,...
Apache License 2.0
78 stars 62 forks source link

Update docs: Access to nested child elements in json field #91

Open keltik85 opened 8 years ago

keltik85 commented 8 years ago

I may be to stupid to read between the lines in the docs, but i cant get the following to work:

def instance = new TestMapJson(data: [name: "Iván", age: 35, hasChilds: true, childs: [[name: 'Judith', age: 8], [name: 'Adriana', age: 5],[name: 'Peter', age: 8]]])
instance.save()
def instance2 = new TestMapJson(data: [name: "Iván", age: 35, hasChilds: true, childs: [[name: 'Judith', age: 38], [name: 'Adriana', age: 25],[name: 'Peter', age: 18]]])
instance2.save()
def instance3 = new TestMapJson(data: [name: "Iván", age: 35, hasChilds: true, childs: [[name: 'Judith', age: 1], [name: 'Adriana', age: 5],[name: 'Andre', age: 8]]])
instance3.save()
//give me instances of TestMapJson, which have at least one child with the age of 8
def result = TestMapJson.withCriteria {
    pgJsonHasFieldValue 'data', 'childs.age', '8'
}
//i would expect instance1 and instance2 to be returned
//give me instances of TestMapJson, which have at least one child with the age of 8 which is named Peter
def result = TestMapJson.withCriteria {
    pgJsonHasFieldValue 'data', 'childs.age', '8'
    pgJsonHasFieldValue 'data', 'childs.name', 'Peter'
}
//i would expect instance1 to be returned

Is there a use case for this or am I trying to do stuff that is not implemented?