Do not override ActiveRecord has_many_through associations to mark and allow cross-joins
There are 2 ways to mark a cross-join currently:
has_many :users, -> {
allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/422405")
}, through: :group_members
Keep the association definition the same, but override in a different method
has_many :users, through: :group_members
def users
super.loaded? ? super : super.allow_cross_joins_across_databases(url: "https://gitlab.com/gitlab-org/gitlab/-/issues/422405")
end
Doing it the (2)nd way can have grave consequences and should be avoided as it can even lead to unintended data loss.
Case in point: !130083 (comment 1544147137)
So we should convert 2 instances of such cross-join allows to the 1st way: