Add relations code and tests.