BACKGROUND: I have Posts and Users, both of which HABTM Communities. In my Post model, I have a method for calculating a post's relevance to a given user by comparing how many communities they have in common as such:
def relevance(user)
(self.communities & user.communities).length
end
OBJECTIVE: To query Posts either by a given relevance i.e.
Post.where(:relevance => 3)
or
to query all posts and sort them by relevance i.e.
Post.all.desc(:relevance)
I know that the user variable is needed there somewhere, just wondering if something like this is possible or if a workaround exists.