resolving many-to-many, many-to-one relationships