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

Delete one version #8

Open
vighnesh1987 opened this issue Nov 6, 2014 · 3 comments
Open

Delete one version #8

vighnesh1987 opened this issue Nov 6, 2014 · 3 comments

Comments

@vighnesh1987
Copy link

I've a Rails model set up with Mongoid::Versioning.

class Post
  include Mongoid::Document
  include Mongoid::Timestamps

  include Mongoid::Versioning

  field :name, type: String
end

I want to delete a specific older version. For eg.

post = Post.create name: 'A'
post.update_attributes name: 'B'
post.update_attributes name: 'C'
post.version #=> 3
post.versions.count #=> 2
first_version = post.versions.first #=> #<Post _id: , created_at: _, updated_at: _, version: 2, name: "B">

I want to delete first_version, but when I try to delete it..

first_version.delete
post.versions.count #=> 1
post.reload
post.versions.count #=> 0

..all versions get deleted.

I've tried using destroy instead, tried running the code inside a block passed to post.versionless, to no avail. This definitely looks like a bug. Am I doing something wrong?

@vighnesh1987
Copy link
Author

I've gotten it to work with Mongoid::Paranoia. But it'd be nice to have the flexibility of not using Mongoid::Paranoia.

@gautamrege
Copy link
Collaborator

I'll take a look.

@gautamrege
Copy link
Collaborator

@vighnesh1987 replied on your stack overflow question http://stackoverflow.com/questions/26770616/mongoidversioning-delete-one-version/26776813

deleted = post.versions.first
post.versions.delete(deleted)

Please re-open if this doesn't work for you.

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

2 participants