Fix loop detection by including associated schema

Fixes (second) bug reported in interagent/prmd#148.