Home How to delete all associated records of Specific record using loop? (not Using dependent)

# How to delete all associated records of Specific record using loop? (not Using dependent)

user4893
1#
user4893 Published in September 19, 2018, 9:46 am

How to delete all associated records of Specific record using a loop? like When I will delete one Specific Seller at that time their related record should be deleted. eg. when One Seller is deleted that time their Products, Customer, SellerMarketplace should be deleted.(Not Marketplace should be deleted.)

class Seller < ActiveRecord::Base
has_many :products
has_many :customers
has_many :seller_marketplaces
has_many :marketplaces through: :seller_marketplaces
end

• I think you need to set the association for seller_marketplaces as well – Deepak Mahakale Apr 12 at 6:25