Prevents stack level too deep on inverse_of relations

When a relation is specified with an inverse_of the association_cache
will loop continuously between the parent and child records causing a
stack level too deep, this fix prevents this by checking for the
presence of the record in the output_hash first, added inverse of to
test models as well to test for this condition.