-
Notifications
You must be signed in to change notification settings - Fork 529
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
Calling with_deleted unscopes all tables with has_many through #534
Comments
This is a huge issue for us, we've been bitten by this behavior many times, and we cannot seem to avoid making the same mistake. Why does |
For what it's worth we added this to our application record and just renamed all of the with_deleted occurances: # This works similar to with_deleted from the paranoia gem.
# However, this will restrict the query to only omit deleted_at
# for the current table_name.
def self.with_omitted(table_name = self.table_name)
unscope(where: { table_name => :deleted_at })
end |
Yeah, we did something similar after I posted this comment, we monkey-patched Paranoia's class Paranoia::Query
def with_deleted
unscope where: { table_name.to_sym => paranoia_column }
end
end |
Assuming you have three models such as User, Posts, Comments all with acts_as_paranoid. If you have associations such as:
Calling
user.comments
would result in SQL with something like the following:calling
users.comments.with_deleted
will in turn callthis will result in all of the
WHERE x.deleted_at IS NULL
being removed.I think that unscope should actually be restricted to the relationship that's being called, for example
with_deleted
here should actually callBefore I submit a pull request I'd like to guage interest in this as it would be quite a breaking change? Any thoughts / comments about how this could be achieved with the least upset to backwards compatibility?
The text was updated successfully, but these errors were encountered: