Add a test for many-to-many relations. Add a per transaction cache to transactions to prevent infinite recursion.