Fixing bug with querying relationships