KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is it possible for a model to belong_to, two models and have a nested relationship? i.e of what i want class trainer has_many :appointments end class appointment belong_to :trainer, :customer end class customer has_many :appointments end at the moment i have only the customer and appointment models which are nested e.g of what i have: create method looks like this: def create @appointment = @customer.appointments.build(params[:appointment]) respond_to do |format| if @appointment.save format.html { redirect_to([@customer, @appointment], :notice => 'Appointment was successfully created.') } format.xml { render :xml => @appointment, :status => :created, :location => @appointment } else format.html { render :action => "new" } format.xml { render :xml => @appointment.errors, :status => :unprocessable_entity } end end end in routes i have: map.resources :patients, :has_many => [ :appointments, :visits ] is it possible to have 2 nested relationships for 1 model? what would i have to change my create method to, if appointment also belonged to trainer as well as customer? thanks
Tags (comma-separated)
Save Edits
Cancel