[odb-users] ODB Query using relation

Adrian Imboden mail at adrianimboden.ch
Mon Jan 6 12:08:22 EST 2014


Hi there

I have a question about ODB queries. I saw many examples where the 
queries are very simple. Now I wanted to query a list of users depending 
on their token, which is a foreign key.

The definitions (removed unused members for now):

#pragma db object optimistic
class User
{
public:
	#pragma db id auto
	uint32_t id = 0;

	std::string name;

	#pragma db column("emailToken")
	std::shared_ptr<Token> emailToken;

	odb::vector<std::shared_ptr<Token>> authTokens

	#pragma db version
	size_t version = 0;
};

#pragma db object optimistic
class Token
{
public:
	#pragma db id auto
	uint32_t id = 0;

	std::string hash;

	boost::posix_time::ptime expirationTime;

	#pragma db version
	size_t version = 0;
};


I want to do two different queries:
1. Find all users that have an emailToken that has a given hash
2. Find all users that have at least one authToken with a given hash

Using SQL I would do a join. Is there something similar possible with 
queries or is this only possible using some views?

Thank you and Greetings
Adrian Imboden

PS: nice project by the way

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3067 bytes
Desc: S/MIME Cryptographic Signature
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20140106/9c8c3d8f/smime.bin


More information about the odb-users mailing list