[odb-users] odb persistence in a library / cross-model dependencies

Christian Sell christian at gsvitec.com
Fri Oct 2 12:38:42 EDT 2015


Hello Boris,
 
note that this issue isn't about schema versioning (although it may have
implications)

> What exactly does "cross-model references" mean, anyway?

in essence, in this case it means that a class from one model wants to subclass
a class from another model. the same would go for relationships, pointers and
the like.

Again: I have model 1, which in my case is compiled into a shared library. Model
1 consist of
 
ClassA
   long number id
ClassB
    vector<shared_ptr<ClassA>> poly_container
 
with mappings defined in a pragma-only header "lib_pragmas.h"
 
#include <ClassA.hpp>
#include <ClassB.hpp>
#pragma db object(ClassA) ypolymorphic
#pragma db member(ClassA::number) id
#pragma db object(ClassB)
 
Now, my application, which uses the above mentioned shared lib, wants to define
a class ClassC which subclasses ClassA. All this should go to the same database,
of course (into the ClassB::poly_container)
 
ClassC -extends->ClassA

with mappings defined as

#include <ClassC.hpp>
#pragma db object(ClassC)
 
Now, when compiling my application, the odb compiler balks that ClassC doesn't
define an id column. The reason is obvious: odb doesn't see the "lib_pragmas.h"
mapping header and thus doesn't know that ClassC's superclass is actually
(polymorphically) mapped and has an id column.

If I then change my application mapping header to 
 
#include <ClassC.hpp>
#include <lib_pragmas.h>
#pragma db object(ClassC)

I can compile, but the generated code replicates the full machinery for ClassA
(and ClassB, for that matter), including  CREATE TABLE statements. I don't see
what I can do from here other than manually editing the generated files..

thanks,
Christian



More information about the odb-users mailing list