[odb-users] aggregate or dis-aggregate a data member
MM
finjulhich at gmail.com
Thu Sep 24 06:45:32 EDT 2015
Hello, I have a need similar to this case from the manual:
consider the need to aggregate or dis-aggregate a data member:
#pragma db object
class person
{
...
#pragma db transient
std::pair<std::string, std::string> name_;
#pragma db member(first) virtual(std::string) access(name_.first)
#pragma db member(last) virtual(std::string) access(name_.second)
};
except that in my case, I have:
class D
{ public:
const std::string& get_type() const;
const std::uint64_t& get_id() const;
}; class C {
public:
const D* d() const;
void d(const D&);
private:
const D* d_;
};
const D* get_D( const std::string& type, std::uint64_t id );
so, I need the d member to map to 2 columns in the table, and the 2 columns
in the table to map back to a single d object, obtained through the get_D()
free function.
I apologize for asking on the list, and I think the answer is quite
straight forward, but I just can't see it :-(
Currently I have:
#pragma db object(C) abstract definition
#pragma db member(C::d) transient
#pragma db member(C::dtype) virtual(std::string)\
get(this.d()? this.d()->get_type(): std::string())\
set()
#pragma db member(C::did) virtual(std::uint64_t)\
get(this.d()? this.d()->get_id(): std::uint64_t())\
set()
For the setting part, I would need both columns to then do the get_D() call.
Rds,
MM
More information about the odb-users
mailing list