Merged
Conversation
rails#36805 have one possible regression that failing deduplication if `joins_values` have complex order (e.g. `joins_values = [join_node_a, :comments, :tags, join_node_a]`). This fixes the deduplication to take it in the first phase before grouping.
Member
|
Going to test this out, I literally just got a reproduction script working 😆 |
Member
|
Yes! This fixes it thank you! For posterity here's the script I got working: require "active_record"
require "minitest/autorun"
require "logger"
ActiveRecord::Base.establish_connection({ "adapter" => "mysql2", "username" => "rails", "database" => "activerecord_unittest" })
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :events, force: true do |t|
t.integer :project_id
end
create_table :event_details, force: true do |t|
t.integer :event_id
end
create_table :projects, force: true do |t|
end
end
class Event < ActiveRecord::Base
has_one :event_detail
belongs_to :project
def self.visible_in_timeline_for
events_for
end
scope :events_for, -> {
join_project.
join_event_detail
}
scope :join_project, -> {
join_event_detail.joins(:project)
}
scope :join_event_detail, -> {
joins(<<~SQL)
INNER JOIN `event_details`
ON `event_details`.`event_id` = `events`.`id`
SQL
}
end
class EventDetail < ActiveRecord::Base
belongs_to :event
end
class Project < ActiveRecord::Base
has_many :events
end
class BugTest < Minitest::Test
def test_scoped_joins
# throws a ActiveRecord::StatementInvalid: Mysql2::Error: Not unique table/alias: 'event_details'
p Event.visible_in_timeline_for
end
end |
Member
Author
|
❤️ Backported 97f1fef. |
This was referenced Sep 2, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#36805 have one possible regression that failing deduplication if
joins_valueshave complex order (e.g.joins_values = [join_node_a, :comments, :tags, join_node_a]).This fixes the deduplication to take it in the first phase before
grouping.
I believe the deduplication issue #36805 (comment) might be fixed by this.
cc @eileencodes