Rails 4: Delete on has_many through association -


Based on an example from the Rail Guide () I wrote the following code:

  Class patients & lt; ActiveRecord :: Base is-Middle: Among the appointments is_mayin: through therapist,: :: Appointment of classrooms for recruitment & lt; ActiveRecord :: Base is_to: Doctor belongs_to: patient and class physician & lt; ActiveRecord :: Base has has_many: Has the appointments has_many: patients, through :: appointments def vips patients. Where (appointments: {VIP: true}) End DEF add_vip patient appointments .create (Patient: Patient, VIP: true) End DEF delete_vip patient vips .delete (patient) End End  

This is that if I have doctor (an example of a physician) and a patient and then

  doctor.ad_wip (patient) doctor. Delete code (patient)  

to delete_vip not only removes the organization, but the example itself

How can I remove only the Sangh?

The association / record that you want to delete is appointment Muscle You are making an appointment in add_vip and it should remove an appointment in delete_vip .

  # Elimits all the appointments without destroying the patient himself. Removing the patient's deaf, _pip patient appointments. Where (Patient: Patient, VIP: True) .delete_all end  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -