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

Added with_deleted option to has_one relationship #324

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marcomd
Copy link

@marcomd marcomd commented Mar 28, 2024

With this PR it is possible to create a has_one relationship of deleted records.
I added two new tests and I also updated the README

class Parent < ActiveRecord::Base
  has_one :child, class_name: "ParanoiacChild"
  has_one :child_with_deleted, class_name: "ParanoiacChild", with_deleted: true
end

class ParanoiacChild < ActiveRecord::Base
  acts_as_paranoid
  belongs_to :parent
end

parent = Parent.first

child = ParanoiacChild.create
parent.child = child

parent.child #=> ParanoiacChild

child.destroy
parent.reload

parent.child #=> nil
parent.child_with_deleted #=> ParanoiacChild

@marcomdiubenda
Copy link

It's like

has_one :child_with_deleted, -> { with_deleted }, class_name: "ParanoiacChild"

It came to mind while I was writing the description . Up to you whether to keep this PR or discard it. However, I find useful the updated README with an example with has_one

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

Successfully merging this pull request may close these issues.

2 participants