Any-to-any fields extension

Has anyone written an extension or knows a smart way to create any to any fields? Meaning a collection of collections that can all link to each other (using a junction table that has id and collection-name for both sides of the connection)?