mongoid-paperclip icon indicating copy to clipboard operation
mongoid-paperclip copied to clipboard

destroy or destroy all on embedded documents doesnt destroy all object.

Open fransstudio2 opened this issue 11 years ago • 2 comments

destroy or destroy all on embedded documents doesnt destroy all object.

person.rb

class Person embeds_many :pictures, :cascading_callback => true end

picture.rb

class Picture embedded_in Person

has_mongoid_attached_file :picture end

in PersonsController

def delete_pictures

if @person.pictures.present? @person.pictures.destroy_all end

end

If beforehand the person database have pictures, this WON'T WORK Properly, somehow. Destroy doesnt delete all of my picture objects.

Even with

@person.pictures.each do |p| p.destroy end

Doesnt do the trick.

My own hack is to use this:

Controller while @person.pictures.present?

@person.pictures.destroy_all doesnt work either, coz after that the pictures array is empty, when on next reload not.

@person.pictures.each do |p| @person.pictures.destroy end end

Can somebody explain to me what did i do wrong?

Thanks!

fransstudio2 avatar Oct 23 '13 09:10 fransstudio2

+1

sunrisela avatar Jun 26 '14 02:06 sunrisela

+1

brand-it avatar Sep 04 '14 15:09 brand-it