[odb-users] let class members default to transient
Boris Kolpackov
boris at codesynthesis.com
Tue Dec 30 08:50:39 EST 2014
Hi Christian,
Christian Sell <christian at gsvitec.com> writes:
> I have several classes which contain only a few members that are
> mapped to the database, while most members are transient only. Now
> I am looking for a way to tell the compiler to only consider those
> members that are explcitly mapped through member pragmas, and leave
> the others alone. Currently, it seems like I have to put a "#pragma
> transient" alongside each of the non-mapped members.
>
> I tried "db object(myclass) transient", but that seems to cause the
> compiler to even ignore the explicitly mapped members..
Yes, you almost got to the solution. The last step in achieving what
you want is to define virtual data members for the ones that are
persistent:
#pragma db object transient
struct my_object
{
... // Lots more data members that we don't want in the database.
unsigned int id_;
std::string str_;
};
#pragma db member(my_object::id) virtual(unsigned int) access(id_) id auto
#pragma db member(my_object::str) virtual(std::string) access(str_)
This mechanism is described in more detail in Section 14.4.13, "virtual".
Boris
More information about the odb-users
mailing list