1772298f2d14152c13bbd3221e6ab6ec

I'm trying to do a join between three tables with constraints and have it return a set of valid users back to me. While this code works as it should, it just seems very messy and I just think Rails would most likely have a very succinct way of doing this. Any ideas?

def matched_members
    matched_members = []
    availabilities.each do |availability|  
      matched_members << User.joins([:group, :availabilities]).where(["groups.id = ? AND users.id <> ? AND availabilities.next = ?", self.group.id, self.id, availability.next])
    end
    matched_members.flatten
  end

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel