I think this will likely be confusing in many cases, since it's trivial to
come up with example where it won't be able to work as expected.

For example, suppose that someone does Article.where("deleted_at IS NULL")
in some method (or even harder to find: in a library), then the result of
that has unscope(where: {articles: :deleted_at}) called on it. In that case
the unscope call will be a no-op, and the result not only surprising, but
likely to cause significant application bugs.

As such, I'm -1 on this change.

On Sat, Feb 29, 2020 at 1:00 AM Slava Korolev <koro...@gmail.com> wrote:

> I often see a use case when in a query, there are several relations with
> attributes with the same names(for example, in our codebase, there are
> several "soft-deletable" entities, and all of them have deleted_at
>  attribute).
>
> Article.where(deleted_at: nil).joins(:comments).where(comments: { deleted_at: 
> nil })
>
> At the moment, it's not possible to unscope deleted_at only for articles
> or only for comments.
>
> I created a PR that adds support for specifying tables in where clauses in
> unscope method:
>
> Article.where(deleted_at: nil).joins(:comments).where(comments: { deleted_at: 
> nil }).unscope(where: { articles: :deleted_at })
>   # == Article.joins(:comments).where(comments: { deleted_at: nil })
>
>
> PR: https://github.com/rails/rails/pull/38608
>
> Happy to get any feedback, thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-core/e5117870-9340-4d86-b81c-0ae75840d486%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-core/e5117870-9340-4d86-b81c-0ae75840d486%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-core/CAAaqYe96zOwnAGvF3_uaiHyXv-LLkYYFy0nfgJGhh%3D6%2B4B7Hrg%40mail.gmail.com.

Reply via email to