My Lab model:
class Lab < ApplicationRecord
has_many :chain_offers, dependent: :delete_all
has_many :offers, through: :chain_offers
class ChainOffer < ApplicationRecord
class Offer < ApplicationRecord
has_many :labs, through: :chain_offers
place = Place.find(place_id)
place.offers.each do |offer|
Your understanding of how a many to many relationship works is simply incorrect.
Lets take this example:
class Patient < ApplicationRecord has_many :appointments, dependent: :destroy has_many :doctors, through: :appointments end class Appointment < ApplicationRecord belongs_to :patient belongs_to :doctor end class Doctor < ApplicationRecord has_many :appointments has_many :doctors, through: :appointments end
If we where to delete a patient with
Patient.find(1).destroy it should also delete any rows on
appointments.patient_id = 1.
It should NOT destroy any rows on the
doctors table! That would remove the doctor from other patients and is not what you want.