AW: [odb-users] making query with nested relationships

Marcel Nehring mne at
Mon Apr 11 08:45:06 EDT 2016

Hi Michaël,

one way that should work is to use an object loading view. There you can specify all three corresponding types of objects (i.e. Event, SubjectDetails and StudentGroup). In your query to load the events you can then filter on each object type separately. It could look like:

#pragma db view object(StudentGroup) object(SubjectDetails inner) object(Event inner)
struct YourView
    Event *event;

Then the query would be something like:

odb::pgsql::query<YourView>::StudentGroup::degree == 1 && odb::pgsql::query<YourView>::StudentGroup::course == 2

When iterating the results you can use the 'event' member of the view to get the matching event.

Have a look at the manual, section 10 (especially subsections 10.2 and 10.5) for the details.


-----Ursprüngliche Nachricht-----
Von: odb-users-bounces at [mailto:odb-users-bounces at] Im Auftrag von Michael Martín Moro
Gesendet: Montag, 11. April 2016 14:06
An: odb-users at
Betreff: [odb-users] making query with nested relationships


I want to make a rather complex query, and I'm wondering how to put it in ODB's terms.

I have these objects:

Event has one SubjectDetails
SubjectDetails has many StudentGroups
StudentGroup has a degree and course attributes.

I need to fetch all the Events who are related to StudentGroups with a given degree and course attribute.

Basically, I would need something such as:
odb::pgsql::query<Event>::subject_details->student_group->degree == 1 && odb::pgsql::query<Event>::subject_details->student_group->course == 2

But I haven't found a way to write such requests yet. I'm not even sure it's possible, even using Views. Maybe I'm not looking in the right direction.

Any help with that would be very welcome.
*Michaël Martín Moro*
{ Epitech. Tek4 }
{ UCA Cadíz - Computer Engineering }

More information about the odb-users mailing list