[odb-users] unique constrain has no effect
Boris Kolpackov
boris at codesynthesis.com
Thu May 30 10:25:02 EDT 2019
Panayiotis Georgiou <ps.georgiou at gmail.com> writes:
> #pragma db object abstract
> class OdbRecord
> {
> //----> // #pragma db type("TEXT") unique
> //----> // #pragma db unique
> std::string m_Label;
> };
The reason you don't get the unique constraint in your schema is
because OdbRecord is abstract and therefore does not result in
a table of its own. One could argue that we should automatically
"propagate" such unique constraints to (all) the derived classes
but we don't do it currently (due to the additional complexity
that such propagation would entail).
One way to make this work is using a virtual data member:
#pragma db object abstract
class OdbRecord
{
#pragma db transient
std::string m_Label;
};
#pragma db object polymorphic
class OdbDerived: public OdbRecord
{
#pragma db member(m_Label_) virtual(std::string) unique access(m_Label)
};
More information about the odb-users
mailing list