Skip to content
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

Add intersects? to Relation #47670

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
* Add support for `Array#intersect?` to `ActiveRecord::Relation`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses intersect? (without an 'S'), but the other files use intersects? (with an 'S'). Perhaps that can be corrected, to help avoid bugs when people copy the method name from the change log?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed in e446ef8, thank you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CHANGELOG is correct, I fixed the code in 119b4b2


`Array#intersect?` is only available on Ruby 3.1 or later.

This allows the Rubocop `Style/ArrayIntersect` cop to work with `ActiveRecord::Relation` objects.

*John Harry Kelly*
john-h-k marked this conversation as resolved.
Show resolved Hide resolved

* The deferrable foreign key can be passed to `t.references`.

*Hiroyuki Ishii*
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def #{method}(...)
# may vary depending on the klass of a relation, so we create a subclass of Relation
# for each different klass, and the delegations are compiled into that subclass only.

delegate :to_xml, :encode_with, :length, :each, :join,
delegate :to_xml, :encode_with, :length, :each, :join, :intersects?,
:[], :&, :|, :+, :-, :sample, :reverse, :rotate, :compact, :in_groups, :in_groups_of,
:to_sentence, :to_fs, :to_formatted_s, :as_json,
:shuffle, :split, :slice, :index, :rindex, to: :records
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/relation/delegation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module ActiveRecord
module DelegationTests
ARRAY_DELEGATES = [
:+, :-, :|, :&, :[], :shuffle,
:+, :-, :|, :&, :[], :shuffle, :intersects?,
:all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index,
:exclude?, :find_all, :flat_map, :group_by, :include?, :length,
:map, :none?, :one?, :partition, :reject, :reverse, :rotate,
Expand Down