NOJIRA Restructured installer code that processes relationship types

There was a weird bug that would cause sub_type_left or right
restrictions to be ignored for the first types in a given relationship
type list. The workaround is a little ugly but it works.

Also, some of this code was very inefficient. We now use API methods to
figure out type IDs instead of weird DB queries.