Skip to content

Instantly share code, notes, and snippets.

@alfie-max
Created August 1, 2016 09:12
Show Gist options
  • Save alfie-max/78b14399ba2599e3099b5b699b23fe45 to your computer and use it in GitHub Desktop.
Save alfie-max/78b14399ba2599e3099b5b699b23fe45 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_many :events, foreign_key: :chef_id, dependent: :destroy
has_many :reservations, foreign_key: :guest_id
has_many :guest_events, -> { merge(Reservation.accepted) },
through: :reservations, source: :event
enum role: [:chef, :guest, :both]
end
class Event < ActiveRecord::Base
has_many :reservations, dependent: :destroy
has_many :accepted_guests, -> { merge(Reservation.accepted) },
through: :reservations, source: :guest
belongs_to :chef, class_name: 'User', required: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment