Skip to content

Instantly share code, notes, and snippets.

@zimkies
Created September 19, 2014 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimkies/72ddbe56ea6433593eb7 to your computer and use it in GitHub Desktop.
Save zimkies/72ddbe56ea6433593eb7 to your computer and use it in GitHub Desktop.
The problem with separating out models into purely their own concerns
# FML You are joking right?
# THere has to be something wrong with this model.
def user_has_been_to_venue?(user, venue)
Reservation.joins("LEFT JOIN venues_tables ON venues_tables.id = reservations.table_id LEFT JOIN venues ON venues_tables.venue_id = venues.id LEFT JOIN groupers ON groupers.id = reservations.grouper_id LEFT JOIN crews ON crews.grouper_id = groupers.id LEFT JOIN users ON users.id = crews.leader_id")
.where("crews.leader_id = ?", user.id)
.where("venues.id = ?", venue.id).exists?
end
@brett-richardson
Copy link

user.groupers.pluck(:venue_id).include? venue.id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment