Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fransstudio2 opened this issue Oct 23, 2013 · 2 comments

Comments

@fransstudio2
Copy link

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!

@sunrisela
Copy link

+1

1 similar comment
@brand-it
Copy link

brand-it commented Sep 4, 2014

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants