[odb-users] Use a view to query many-to-many relationship
Boris Kolpackov
boris at codesynthesis.com
Thu Sep 27 21:24:53 EDT 2018
Lukas Barth <lists at tinloaf.de> writes:
> However, now there's a to-many relationship to the ConfigKVs. How do I
> formulate a view / a query on a view that only selects the entries that
> have exactly the right ConfigKVs associated? Basically, I'd need a magic
> "contains" and "size" predicates in the query language like this:
>
> db->query(query<my_view>::value == 42 &&
> query<my_view>::cfg->kvs->contains(
> query<ConfigKV>::key == 'foo' &&
> query<ConfigKV>::value == 'bar') &&
> query<my_view>::cfg->kvs->contains(
> query<ConfigKV>::key == 'fuz' &&
> query<ConfigKV>::value == 'baz') &&
> query<my_view>::cfg->kvs->size() == 2)
>
> Note that I modeled the 'exactly the two required KV mappings' by asking
> for both to be contained and then querying for the size to be exactly
> two. Are there any such predicates in the query language? Or is there a
> different way of formulating this?
There is no query support for containers yet and whether it is actually
doable is not clear (you used the word "magic" and that's pretty accurate --
the complexity will be significant).
So currently the two ways to achieve this are:
1. With a raw SQL and a native view.
2. By re-formulating your containers in terms of objects and
relationships (which are supported by the query language).
More information about the odb-users
mailing list