In my application a user can create an appointment.
class User
has_many :appointments
end
class Appointment
belongs_to :user
end
However, a user can also join another appointment created by another user.
Could someone recommend a way to set up my models?
I’ve been reading through http://guides.rubyonrails.org/association_basics.html and cannot find the correct association.
I’m really keen to do this the rails way, rather than hacking my application about.
Would has_and_belongs_to_many be the way to go?
Sounds like you probably want to use
has_manywith some kind of model describing the relationship between users and appointments:Of course, you’ll probably also want to represent the owner of the appointment. You could expand your
Appointmentmodel to reflect who actually owns it. You could provide a relationship field inUserAppointmentto describe whether a user is an owner or subscriber, but it might be easier to simply add abelongs_torelationship to the appointment model: