Skip to content

Commit

Permalink
Revert "Merge pull request rails#48487 from lazaronixon/scope-subquer…
Browse files Browse the repository at this point in the history
…ies"

This reverts commit 6264c1d, reversing
changes made to 6c80bcd.

Reason: Still discussion about the feature. We want to make it opt-in
but we need to better understand why people would want to opt-in to
this behavior.
  • Loading branch information
rafaelfranca committed Jun 29, 2023
1 parent b214c07 commit e366af5
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 30 deletions.
18 changes: 0 additions & 18 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@

*Cadu Ribeiro and Jorge Manrubia*

* Apply scope to association subqueries. (belongs_to/has_one/has_many)

Given: `has_many :welcome_posts, -> { where(title: "welcome") }`

Before:
```ruby
Author.where(welcome_posts: Post.all)
#=> SELECT (...) WHERE "authors"."id" IN (SELECT "posts"."author_id" FROM "posts")
```

Later:
```ruby
Author.where(welcome_posts: Post.all)
#=> SELECT (...) WHERE "authors"."id" IN (SELECT "posts"."author_id" FROM "posts" WHERE "posts"."title" = 'welcome')
```

*Lázaro Nixon*

* Added PostgreSQL migration commands for enum rename, add value, and rename value.

`rename_enum` and `rename_enum_value` are reversible. Due to Postgres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def ids
case value
when Relation
relation = value
relation = relation.merge(scope) if scope
relation = relation.select(primary_key) if select_clause?
relation = relation.where(primary_type => polymorphic_name) if polymorphic_clause?
relation
Expand All @@ -49,10 +48,6 @@ def polymorphic_name
associated_table.polymorphic_name_association
end

def scope
associated_table.scope
end

def select_clause?
value.select_values.empty?
end
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/table_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ActiveRecord
class TableMetadata # :nodoc:
delegate :join_primary_key, :join_primary_type, :join_foreign_key, :join_foreign_type, :scope, to: :reflection
delegate :join_primary_key, :join_primary_type, :join_foreign_key, :join_foreign_type, to: :reflection

def initialize(klass, arel_table, reflection = nil)
@klass = klass
Expand Down
6 changes: 0 additions & 6 deletions activerecord/test/cases/relation/where_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,6 @@ def test_where_on_association_with_collection_polymorphic_relation
assert_equal [treasures(:diamond)], treasures
end

def test_where_on_association_with_scoped_relation
authors = Author.where(welcome_posts: Post.all)
assert_equal 1, authors.count
assert_equal authors(:david), authors.first
end

def test_where_with_strong_parameters
author = authors(:david)
params = ProtectedParams.new(name: author.name)
Expand Down

0 comments on commit e366af5

Please sign in to comment.