Fixed bug not to restore association records#30
Conversation
|
Hello @kouyaf77. Thanks for your pull request. Can you provide a little info why this change is needed? What's the usecase? Why you couldn't get association records via |
|
Hi @simi class User
include Mongoid::Document
include Mongoid::Paranoia
has_many :posts, dependent: :destroy
end
class Post
include Mongoid::Document
include Mongoid::Paranoia
belongs_to :user
endThen, we can't restore association records in case of following. User.create posts: Post.create
user = User.first
user.destroy
user = User.unscoped.first
user.restore(recursive: true) |
|
The reason not to get association records is to work default scope. |
|
@kouyaf77 Thank you for the PR and for fixing the tests. I'm a bit concerned about the change to |
|
Just looking at this again. Another option would be to move the deleted key to a shadow field (e.g. Again the main reason I don't like the solution in the PR is that it leaves you with a relation reference to a deleted object, which is a "messy" data state that doesn't (shouldn't) occur naturally in Mongoid. |
Actually, we couldn't get association records at
relation = self.send(name)oflib/mongoid/paranoia.rb.In Rspec,
subjecthad reference. But instance doesn't have reference when we use excepting Rspec.So I fixed it.
Thx