I had a doozy of a bug today: an “Album” model has_many “Track” objects, but calling album.tracks.clear was not deleting or destroying the associated tracks in spite of my having explicitly set :dependent => :destroy on the has_many association.

As it turns out, my object (the album) was being stored in the session, and therefore the associated tracks were also in the session. When I called album.tracks.clear, the foreign keys were nullified instead of the rows destroyed.

The solution: store album ids in the session instead of the whole object, and do an Album.find(session[:album_id]).