I am working on a project which has a very similar quandary to this ask: Ordering by number of associations in common (Rails)
The asker of said ask (Neon) writes,
BACKGROUND: I have Posts and Users, and both have many Communities.
OBJECTIVE: For any given User I'd like to return a collection of Posts, ordered by how many communities the post has in common with the user (posts with more communities in-common being higher up)
Unfortunately, the solution only includes posts that have at least one common community. My quandry needs to include all posts ordered by the number of common communities.
EXTENDED OBJECTIVE: The result must be an AREL object with all posts ordered by the number of common communities, including posts with zero communities in common with the user (posts with more communities in-common being higher up).