From 25ee467afb3735cfa74f94c1b2a4934621cad4b7 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 17 Nov 2019 23:37:06 +0900 Subject: [PATCH] Avoid implicit `scoped_model.all` delegation in the validation (#52) Validations are sometimes called in the deprecated leaking scoping https://github.com/rails/rails/pull/35280 (e.g. `find_or_create_by` etc). To avoid that warning, we should not delegate to (implicit) `scoped_model.all`. Fixes #51. --- lib/validates_overlap/overlap_validator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/validates_overlap/overlap_validator.rb b/lib/validates_overlap/overlap_validator.rb index f762821..5ac19f0 100644 --- a/lib/validates_overlap/overlap_validator.rb +++ b/lib/validates_overlap/overlap_validator.rb @@ -40,7 +40,8 @@ def validate(record) protected def initialize_query(record, options = {}) - self.scoped_model = options[:scoped_model].present? ? options[:scoped_model].constantize : record.class + scoped_model = options[:scoped_model].present? ? options[:scoped_model].constantize : record.class + self.scoped_model = scoped_model.default_scoped generate_overlap_sql_values(record) generate_overlap_sql_conditions(record) add_attributes(record, options[:scope]) if options && options[:scope].present?