[odb-users] Query on many-to-one for "contains an object with property X"

Lukas Barth lists at tinloaf.de
Wed Nov 8 09:11:41 EST 2017


in my database model I have a many-to-one relationship between A and B, 
with multiple B being associated with one A. The inverse field is 
declared, something along the lines of:

==================== snip ====================
#pragma db object
class B
   int value;

   #pragma db not_null
   shared_ptr<A> a;

#pragma db object
class A
#pragma db inverse(a)
  std::vector<std::shared_ptr<B>> bs;
==================== snip ====================

I now want to query for all As that have a B with a value of 42 
associated with them. I can't find the syntax for that (if that's 
possible) in the documentation. I would assume that I can access "bs" as 
as a field of A, but then I would need a "contains" operator and 
something to build the nested query, something along the lines of this:

db.query<A> (query::bs->contains( query<B>(query::value == 42) ))

Is something like this possible?

Thanks a lot!


More information about the odb-users mailing list