Class: ParamsReady::Query::ExistsPredicate
- Inherits:
-
StructuredGrouping
- Object
- Parameter::AbstractParameter
- Parameter::Parameter
- Parameter::AbstractStructParameter
- Parameter::StructParameter
- StructuredGrouping
- ParamsReady::Query::ExistsPredicate
- Includes:
- Predicate::HavingAssociations
- Defined in:
- lib/params_ready/query/exists_predicate.rb
Constant Summary
Constants inherited from Parameter::AbstractStructParameter
Parameter::AbstractStructParameter::EMPTY_HASH
Instance Attribute Summary
Attributes inherited from Parameter::AbstractParameter
Instance Method Summary collapse
- #related(query_table, subquery_table, context) ⇒ Object
- #test(record) ⇒ Object
- #to_query(query_table, context: Restriction.blanket_permission) ⇒ Object
Methods included from Predicate::HavingAssociations
Methods inherited from StructuredGrouping
#context_for_predicates, #operator, #predicates
Methods included from Parameter::GroupingLike
#eligible_for_query?, #predicate_group, #to_query_if_eligible
Methods included from Marshaller::ParameterModule
Methods inherited from Parameter::AbstractStructParameter
#[], #[]=, #find_in_hash, #for_frontend, #for_model, #for_output, #wrap_output
Methods included from Parameter::ComplexParameter
Methods inherited from Parameter::Parameter
#allows_undefined?, #definite_default?, #eligible_for_output?, #find_in_hash, #format, #format_self_permitted, #freeze, #hash, #hash_key, #initialize, #inspect_content, #is_default?, #is_definite?, #is_nil?, #is_undefined?, #memo, #memo!, #nil_default?, #populate_other, #set_from_input, #set_value, #to_hash_if_eligible, #unwrap, #unwrap_or, #wrap_output
Methods inherited from Parameter::AbstractParameter
#==, #dup, #initialize, #inspect, intent_for_children, #match?, #populate, #to_hash, #update_if_applicable, #update_in
Methods included from Extensions::Freezer
#freeze_variable, #freeze_variables, #variables_to_freeze
Methods included from Parameter::FromHash
Methods included from Extensions::Freezer::InstanceMethods
Constructor Details
This class inherits a constructor from ParamsReady::Parameter::Parameter
Instance Method Details
#related(query_table, subquery_table, context) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/params_ready/query/exists_predicate.rb', line 29 def (query_table, subquery_table, context) return nil if definition..nil? grouping = definition..to_arel(query_table, subquery_table, context, self) subquery_table.grouping(grouping) end |
#test(record) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/params_ready/query/exists_predicate.rb', line 36 def test(record) return nil unless is_definite? collection = dig(record, definition.path_to_collection) result = if collection.nil? false else collection.any? do |item| super item end end if definition.has_child?(:existence) && self[:existence].unwrap == :none !result else result end end |
#to_query(query_table, context: Restriction.blanket_permission) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/params_ready/query/exists_predicate.rb', line 10 def to_query(query_table, context: Restriction.) query_table = definition.outer_table || query_table subquery_table = self.definition.arel_table raise ParamsReadyError, "Arel table for '#{name}' not set" if subquery_table.nil? predicates = predicate_group(subquery_table, context: context) join_clause = self. query_table, subquery_table, context subquery = GroupingOperator.instance(:and).connect(predicates, join_clause) select = subquery_table.where(subquery) query = select.take(1).project(Arel.star).exists if definition.has_child?(:existence) && self[:existence].unwrap == :none query.not else query end end |