Skip to content

Delete one version #8

@vighnesh1987

Description

@vighnesh1987

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions