Memoize relation lookup.
Test cases for #relations.