ActsAsParanoid / acts_as_paranoid

ActiveRecord plugin allowing you to hide and restore records without actually deleting them.
MIT License
1.47k stars 192 forks source link

Rails 6 issues with only_deleted with_deleted scopes #205

Open unlimit opened 3 years ago

unlimit commented 3 years ago

Hi! We recently switched our app to Rails 6(6.1.2) and we noticed that only_deleted and with_deleted scopes doesn't work properly via associations

class User < ApplicationRecord
  acts_as_paranoid
  belongs_to :company
end

class Company < ApplicationRecord
  acts_as_paranoid
  has_many :users
end

c = Company.find 1
c.users.only_deleted.count

generates sql: SELECT COUNT() FROM "users" WHERE "users"."deleted_at" IS NOT NULL expecting sql: SELECT COUNT() FROM "users" WHERE "users"."company_id" = $1 AND "users"."deleted_at" IS NOT NULL

jprince commented 3 years ago

@unlimit I know this is a few months old, but I was experiencing a similar issue and upgrading to v0.7.3 resolved it.

mvz commented 3 years ago

@unlimit can you confirm that acts_as_paranoid 0.7.3 resolves your problem?

jshah commented 2 years ago

I was getting NoMethodError: undefined method equality?' when using only_deleted and upgrading to v0.7.3 fixed it for me.

mvz commented 2 years ago

@jshah how is that related to the original bug report?