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:

Ruby: 3.1.3
Rails: 7.0.4
Ransack: 3.2.1

Basic Setup

# -- Intervention Model --
class Intervention < ApplicationRecord

  belongs_to :father, class_name: "Intervention", foreign_key: "intervention_id", optional: true
  has_one :child, class_name: "Intervention", foreign_key: "intervention_id", dependent: :destroy

  scope :neither_father_nor_child, -> { where.missing(:father, :child) }

  def self.ransackable_scopes(auth_object = nil)
     %i[neither_father_nor_child]
  end
end

h = {:g=>{"0"=>{:neither_father_nor_child=>1}}}

Intervention.ransack(h) # => Ransack::Search<class: Intervention, base: Grouping <combinator: and>>
Intervention.ransack(h).result.to_sql # => SELECT \"interventions\".* FROM \"interventions\"

It is not calling the defined scope, but if i try

Intervention.ransack(neither_father_nor_child: 1) => # Ransack::Search<class: Intervention, scope: {"neither_father_nor_child"=>1}, base: Grouping <combinator: and>

So I don't know where is the problem


Additional instructions:

Add A PR with only a failing test

Fixes #1490


💬 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.

Ransack doesn't lookup scope when using groupings
2 participants