You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling user.comments would result in SQL with something like the following:
SELECT comments.*FROM comments
INNER JOIN posts ONcomments.post_id=posts.idINNER JOIN users onposts.user_id=users.idWHEREcomments.deleted_at IS NULLANDposts.deleted_at IS NULLANDusers.deleted_at IS NULLANDuser.id=1
calling users.comments.with_deleted will in turn call
unscope(where: :deleted_at)
this 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 call
unscope(where: {comments: :with_deleted})
Before 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:
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 with_deleted get applied to all tables in a joined association dataset, is it intended behavior? Because it sure does seem like a bug to me.
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 with_deleted get applied to all tables in a joined association dataset, is it intended behavior? Because it sure does seem like a bug to me.
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.defself.with_omitted(table_name=self.table_name)unscope(where: {table_name=>:deleted_at})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: