issue #22244: refactor document associations

Not ready for pull yet

TODO: need a compound inverse in case of duplicate source key

resolves #1962.
This should be documented in the code, both here and in `data.sql` with cross-references. Otherwise it'll be too easy to mess up one end or the other.