[odb-users] Query a many-to-many relationship

Boris Kolpackov boris at codesynthesis.com
Mon Jul 6 12:37:59 EDT 2015


Hi Dieter,

dieter.govaerts at bricsys.com <dieter.govaerts at bricsys.com> writes:

> I've been though all example projects (2.3.0) but I don't seem to find
> an easy way to query objects based on a many-to-many relationship.
> 
> Referring to the 'relationship' example project, how can I query all
> employees working on project "Complex Hardware"?

That is actually not a to-many relationship, so you can use normal
object queries:

typedef odb::query<employee> query;

db.query<employee> (query::employer->name == "Complex Hardware");

For real to-many relationships you would use a view. If you want
to load the whole object, then you would use an object loading view
(Section 10.2 in the ODB manual; available since 2.4.0).

Boris



More information about the odb-users mailing list