[odb-users] ODB polymorphic inheritence problem
Alexander Konin
aakmail at mail.ru
Sat Mar 30 15:48:02 EDT 2013
Hi,
I am upgrading from ODB 1.8 to ODB 2.2. And there is problem with polymorphic inheritance. Consider the following hierarchy:
Item <- Parent <- Segment. Item contains pointer to Parent, and Parent has list of contained Items, but concreate Parent descendants declare this list (or lists). So, we have one-to-many relation, and I use inversion on "many" side:
==== File Item.h
class Parent;
// Root class of some subsystem, has reference (parent_) to parent class
#pragma db object polymorphic table("Items")
class Item
{
private:
#pragma db id auto
int id_;
#pragma db null
Parent* parent_;
...
};
#ifdef ODB_COMPILER
#include "Parent.h"
#endif
==== File Parent.h
// Class that designates parent node
#pragma db object table("Parents")
class Parent : public Item
{
// This class has no members, but descendants have lists of parented items
...
};
==== File Segment.h
// A class that is Parent. Segment contains other segments as its children.
#pragma db object table("Segments")
class Segment : public Parent, public Segmentable
{
private:
#pragma db value_not_null inverse(parent_)
QList<Segment*> segments_;
...
};
The problem is that ODB generates incorrect SQL instructions for loading Segment::segments_:
==== File Segment-odb.cxx:
const char access::object_traits_impl< ::Database::Segment, id_pgsql >::segments_traits::
select_statement[] =
"SELECT "
"\"Segments\".\"id\""
" FROM \"Segments\""
" WHERE \"Segments\".\"parent\"=$1";
"parent" field is contained in "Items" table (we have Item::parent_), not "Segments" table!
How can I solve the problem, or there is not possible?
Thanks in advance,
Alexander Konin
More information about the odb-users
mailing list