Method: Praxis::Extensions::AttributeFiltering::ActiveRecordFilterQueryBuilder.valid_path?
- Defined in:
- lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb
.valid_path?(model, path) ⇒ Boolean
not in filters.…checks if it’s a valid path array of strings
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb', line 126 def self.valid_path?(model, path) first_component, *rest = path if model.attribute_names.include?(first_component) true elsif model.reflections.keys.include?(first_component) if rest.empty? true # Allow associations as a leaf too (as they can have the ! and !! operator) else # Follow the association nested_model = model.reflections[first_component].klass valid_path?(nested_model, rest) end else false end end |