[WIP] Workaround a bug with self referential joins

Currently, two different SQL queries are generated
if the M:1 relationship is either defined before,
or after the 1:N relationship. I suspect that this
has something to do with picking up JoinDefinition
instances from relationships, but I don't have the
time to investigate further now.