I have a Postgres JSONB field, with some nested arrays and other objects.
from sqlalchemy.dialects.postgresql import JSONB
class Family(db.Model):
meta = db.Column(JSONB)
joes = Family(meta=[
{
"name": "Joe",
"children": [
{
"name": "Jane"
},
{
"name": "Kate"
}
]
},
{
"name": "Lisa",
"children": [
{
"name": "Mary"
},
{
"name": "David"
}
]
},
])
Is there a way to query all the kids with a certain substring in their names?
If I want to query for 'a' it should get me Mary, David, Kate, Jane.
I was thinking, maybe something like
Family.query.filter(
Family.meta.contains([{"children": [{"name": func.contains("a")}]}])
)