Skip to content

Instantly share code, notes, and snippets.

@mikecmpbll
Last active August 29, 2015 14:02
Show Gist options
  • Save mikecmpbll/a891560d099e0338df9f to your computer and use it in GitHub Desktop.
Save mikecmpbll/a891560d099e0338df9f to your computer and use it in GitHub Desktop.
class Party < AR::Base
belongs_to :user
belongs_to :session
end
class Session < AR::Base
has_many :parties
has_many :users, through: :parties
end
class User < AR::Base
has_many :parties
has_many :sessions, through: :parties
has_many :fellow_party_animals2, -> { where.not(id: self.id).uniq }, through: :sessions, class_name: "User"
def fellow_party_animals
User.joins(:sessions).where(sessions: { id: sessions }).where.not(id: id).uniq
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment