[odb-users] Join Between Tables

Boris Kolpackov boris at codesynthesis.com
Thu Jun 6 16:01:06 EDT 2013


Hi Tarik,

Tarik BENZ <tenchu.tarik at hotmail.fr> writes:

> I Have three tables that I mapped, and I would like to know
> how to do a join between them. Do I necessarily need to create a view?

ODB automatically creates a JOIN in two cases (well, technically, there
is a third case: polymorphic objects, but that is not generally visible
to the end user):

1. When there is a relationship between objects (i.e., one points to
   the other). In this case, ODB "JOIN's in" the pointed-to objects in
   queries so that you can refer to data members from these objects.
   For example:

   db.query<employee> (query<employee>::employer->name == "Example, Inc");

   Note that this JOIN'ing of related objects is only done one level
   deep.

2. In views that are based on more than one object (or database
   table). There is a lot of flexibility in views and you can JOIN
   objects and/or database tables using relationships and/or custom
   conditions.

So, unless the JOIN that you are looking for naturally follows from
the relationship between your objects, the views are probably your
best choice.

Boris



More information about the odb-users mailing list