[odb-users] Question about join type for polymorphic objects
Енакаев Алексей
Aleksey.Enakaev at infotecs.ru
Fri May 8 05:43:28 EDT 2015
Hi.
We have a question about join type generated for polymorphic objects.
Let's see at this sample code:
#pragma db object polymorphic
struct person { /* id, name, etc. */ };
#pragma db object
struct employee : person { /* position, etc. */ };
For object "employee" ODB compiler generates something like this:
SELECT * FROM "employee" LEFT JOIN "person" ON "person"."id" =
"person"."id" ... etc.
but PostgreSQL can not use "LEFT JOIN" with "FOR UPDATE". Code
using query = odb::query< person >;
const query q = (query::id == some_id && query::name == some_name) +
"for update";
causes PostgreSQL error "FOR UPDATE cannot be applied to the nullable
side of an outer join". So we have to write some extras:
const query q = (query::id == some_id && query::name == some_name) +
"for update of" + odb::object_traits_impl< employee, id_pgsql >::table_name;
Is there any way to explicit join type for polymorphic objects? And
doesn't is look more reasonable to use INNER JOIN always for this kind
of objects?
Best regards.
More information about the odb-users
mailing list