Issue #51: Filter based on relations

Fixes #51