From 066910d722bfea01cbb89557efe3477a1304d317 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 22 Oct 2022 00:29:13 -0500 Subject: [PATCH] defautl_scope implemented --- lib/pg_search/configuration.rb | 8 +++++++- lib/pg_search/scope_options.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pg_search/configuration.rb b/lib/pg_search/configuration.rb index ce37edf9..ceadb40e 100644 --- a/lib/pg_search/configuration.rb +++ b/lib/pg_search/configuration.rb @@ -23,6 +23,12 @@ def alias(*strings) end end + def default_scope + return nil unless options[:default_scope] + + options[:default_scope] + end + def columns regular_columns + associated_columns end @@ -84,7 +90,7 @@ def default_options end VALID_KEYS = %w[ - against ranked_by ignoring using query associated_against order_within_rank + against ranked_by ignoring using query associated_against order_within_rank default_scope ].map(&:to_sym) VALID_VALUES = { diff --git a/lib/pg_search/scope_options.rb b/lib/pg_search/scope_options.rb index 369a603a..3e48cfd3 100644 --- a/lib/pg_search/scope_options.rb +++ b/lib/pg_search/scope_options.rb @@ -84,6 +84,7 @@ def subquery .select("#{primary_key} AS pg_search_id") .select("#{rank} AS rank") .joins(subquery_join) + .where(config.default_scope) .where(conditions) .limit(nil) .offset(nil)