[odb-users] Loading persistent object using custom joins
Patrick Rotsaert
Patrick.Rotsaert at intoit.be
Sun Mar 3 11:19:30 EST 2013
Hi,
I'm trying to find a way to load persistent objects using a join.
I know joins can be done with views, but if I understand correctly, views contain only a subset of the objects involved. I'm interested in the 'complete' objects and possible operate on them.
Consider following 2 objects:
#pragma db object
class employer
{
...
#pragma db id
unsigned long id_;
std::string name_;
};
#pragma db object
class employee
{
...
#pragma db id
unsigned long id_;
std::string first_;
std::string last_;
unsigned short age_;
shared_ptr<employer> employer_;
};
Suppose I'd like to query all employers that have employees under 30 years of age.
In SQL speak, that would be something like:
SELECT DISTINCT employer.*
FROM employee
NATURAL JOIN employer
WHERE employee.age < 30
How can this be done, so I have an odb::result<employer> to work with?
Thanks,
Pat
More information about the odb-users
mailing list