[odb-users] let class members default to transient
christian at gsvitec.com
Thu Jan 1 08:07:50 EST 2015
ah, thanks. Since my objective was to simplify the whole process, I think I will
stick with explicitly declaring all non-mapped members as transient.
> Boris Kolpackov <boris at codesynthesis.com> hat am 30. Dezember 2014 um 14:50
> 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
> #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".
More information about the odb-users