Fixing id-based queries for relationships. Added more test cases.