Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 24, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

Is this expected?

class Children < ActiveRecord::Base
  belongs_to :parent
  has_one :a_ancestor, through: :parent
  has_one :b_ancestor, through: :parent
  has_one :c_ancestor, through: :parent
end

class Parent < ActiveRecord::Base
  belongs_to :a_ancestor
  belongs_to :b_ancestor
  belongs_to :c_ancestor
end

class AAncestor < ActiveRecord::Base; end
class BAncestor < ActiveRecord::Base; end
class CAncestor < ActiveRecord::Base; end

Children.ransack(
  a_ancestor_id_eq: 1,
  b_ancestor_id_eq: 1,
  c_ancestor_id_eq: 1,
).result.to_sql

# => LEFT OUTER JOINs `parents` 3 times

Here's executable test of the issue

https://gist.github.com/Liooo/ea4629204f7f3233633125e5f134b574


Additional instructions:

Determine if this is a problem and if so then create a failing PR in one comment and fixes in the next commit

Fixes #986


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

duplicate JOIN statement searching on multiple has_one though association
2 participants