User
has_many :reservations, :dependent => :destroy
has_many :events, :through => :reservations
Reservation
belongs_to :user
belongs_to :event
Event
has_many :reservations, :dependent => :destroy
has_many :attendees, :through => :reservations, :source => :user
What I want is a method on User
that I can query to find out the status of that user at a given event. Something like:
def attendee_status(event)
res = self.reservations.where(event: event.id).first
if res
res.status
else
0
end
end
I'm confused by the association syntax, among other things...column reservations.event does not exist
each user should only have one reservation for any particular event...first
assumes that. (better way?)
anyway, the status
method on Reservation
model should return one of %w[not_attending, awaiting_payment, payment_received]
what's the "Rails way" to handle these relationship/look-ups from model to model (perhaps even starting with a clearer method name: attendee_status(event)
)?!?