class Cart < ApplicationRecord has_many :items, dependent: :destroy end cart.items = [item1, item2] cart.items = [item3] # item1, item2はDBから削除される