Added support for querying foreign key ids. Fixes #6