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

Ransack doesn't lookup scope when using groupings #1490

Open
devsheva opened this issue Apr 30, 2024 · 0 comments
Open

Ransack doesn't lookup scope when using groupings #1490

devsheva opened this issue Apr 30, 2024 · 0 comments

Comments

@devsheva
Copy link

devsheva commented Apr 30, 2024

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

@devsheva devsheva changed the title Ransack doesn't lookup scope when using hash with numbers as keys Ransack doesn't lookup scope when using groupings Apr 30, 2024
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

No branches or pull requests

1 participant