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

dieter.govaerts at bricsys.com dieter.govaerts at bricsys.com
Mon Jul 6 15:09:16 EDT 2015

Hello Boris,

On Monday, 6 July, 2015 18:37, "Boris Kolpackov" <boris at codesynthesis.com> said:

> 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).

I wanted to query employees based on the name of the _projects_ they work on,
not its employers name.

Object loading views seems indeed the key. I'll have to upgrade to 2.4.0 and
try again.

Thank you.


More information about the odb-users mailing list