Merges in additional filters when querying the collection
 @return [Collection<Model>]
494824
def where(filters)
      raise ModelNotFilterableError, model unless model.filterable?

      self.class.new(model: model, api: api, constraints: constraints.merge(where: filters))
    end
383230
def filter(self, **kwargs):
        
        if kwargs:
            assert self.query.can_filter(), "Cannot filter a query once a slice has been taken."

        clone = self._clone()
        clone.query.add_filters(**kwargs)

        return clone
568808
def inspect
      objects = collection
        .map { |id, _| cached(id) || klass.new(klass.schema.primary_key => id) }
        .map { |object| object.to_s }

      "#<#{self.class.name} [#{objects.join(', ')}]>"
    end
472911
def add_filters( *args )
    args.flatten.each do |filter|
      next if filter.nil?
      unless filter.kind_of?(::Logging::Filter)
        raise TypeError, "#{filter.inspect} is not a kind of 'Logging::Filter'"
      end
      @filters << filter
    end
    self
  end
1296806
def query_all(self):
        
        return self.query_model(self.model, self.condition, order_by=self.order_by,
                                group_by=self.group_by, having=self.having)
748997
def merge(other)
      old_attributes = attributes
      other_attributes = other.is_a?(Hash) ? other : other.attributes

      old_attributes.merge!(other_attributes) do |key, old_value, new_value|
        case key
        when :clusters, :contexts, :users
          old_value + new_value.reject do |new_mapping|
            old_value.any? { |old_mapping| old_mapping[:name] == new_mapping[:name] }
          end
        else
          case old_value
          when Array
            (old_value + new_value).uniq
          when Hash
            old_value.merge(new_value) do |_key, inner_old_value, inner_new_value|
              inner_old_value.nil? ? inner_new_value : inner_old_value
            end
          when NilClass
            new_value
          else
            warn "key is #{key} old val is #{old_value.inspect} and new val is #{new_value.inspect}"
            old_value
          end
        end
      end

      self.class.new(old_attributes)
    end
322877
def filter(self, filter):
        
        new_query_set = self.clone()
        new_query_set.query.add_filter(filter)
        
        return new_query_set
1222716
def results
      ActiveRecord::Base.connection.tables.each do |table|
        model = table.classify.constantize rescue next

        model.columns.each do |column|
          present = model.respond_to?(:nillify_attributes) && model.nillify_attributes.include?(column.name.to_sym)

          @results << [present, model.name, column.name] if include_column(column)
        end
      end

      @results
    end
11612
private function query()
    {
        foreach ($this->search_models as $model_name => $filters) {
            // Apply search against the original model.
            if ($model_name === 'self') {
                self::applySearch($this->query, $filters);
                continue;
            }

            // Apply search against the related model.
            $this->query->whereHas($model_name, function ($query) use ($filters) {
                self::applySearch($query, $filters);
            });
        }

        return $this->query;
    }
1357573
def get_models(self, columns=None):
        
        results = self.apply_scopes().get_query().get(columns).all()

        connection = self._model.get_connection_name()

        models = self._model.hydrate(results, connection)

        return models
97504
function() {
    var model = this.definition.model
    var collection = model.include.apply(
      model,
      this.definition.store.utils.args(arguments)
    )

    // add the current record to the collection
    collection.addInternal('data_loaded', [this.clearRelations()]) // clear relations for start with a clean record
    collection.first()

    return collection
  }
545851
def apply_filters(options)
      return unless options.key?(:only) || options.key?(:except)

      attributes_only_filters, associations_only_filters = resolve_filters(options, :only)
      attributes_except_filters, associations_except_filters = resolve_filters(options, :except)

      self.attributes = apply_attribute_filters(
        attributes,
        attributes_only_filters,
        attributes_except_filters
      )

      self.method_fields = apply_attribute_filters(
        method_fields,
        attributes_only_filters,
        attributes_except_filters
      )

      unless has_many_associations.empty?
        self.has_many_associations = apply_association_filters(
          has_many_associations,
          { attributes: attributes_only_filters, associations: associations_only_filters },
          attributes: attributes_except_filters, associations: associations_except_filters
        )
      end

      unless has_one_associations.empty?
        self.has_one_associations = apply_association_filters(
          has_one_associations,
          { attributes: attributes_only_filters, associations: associations_only_filters },
          attributes: attributes_except_filters, associations: associations_except_filters
        )
      end
    end
887758
def read_new_model(method_name)
      if @persistor && @persistor.respond_to?(:read_new_model)
        return @persistor.read_new_model(method_name)
      else
        opts = @options.merge(parent: self, path: path + [method_name])

        if method_name.plural?
          return new_array_model([], opts)
        else
          return new_model({}, opts)
        end
      end
    end
84539
def all(self):
        
        logger.debug(f'Query `{self.__class__.__name__}` objects with filters {self}')

        # Destroy any cached results
        self._result_cache = None

        # Fetch Model class and connected repository from Repository Factory
        model_cls = repo_factory.get_model(self._entity_cls)
        repository = repo_factory.get_repository(self._entity_cls)

        # order_by clause must be list of keys
        order_by = self._entity_cls.meta_.order_by if not self._order_by else self._order_by

        # Call the read method of the repository
        results = repository.filter(self._criteria, self._offset, self._limit, order_by)

        # Convert the returned results to entity and return it
        entity_items = []
        for item in results.items:
            entity = model_cls.to_entity(item)
            entity.state_.mark_retrieved()
            entity_items.append(entity)
        results.items = entity_items

        # Cache results
        self._result_cache = results

        return results
1065712
def _add_filters(self, **filters):
        """"""
        for key, value in filters.items():
            if self._field_is_pk(key):
                pk = self.cls.get_field('pk').normalize(value)
                self._lazy_collection['pks'].add(pk)
            else:
                # store the info to call the index later, in ``_prepare_sets``
                # (to avoid doing extra work if the collection is never called)
                index, suffix, extra_field_parts = self._parse_filter_key(key)
                parsed_filter = ParsedFilter(index, suffix, extra_field_parts, value)
                self._lazy_collection['sets'].append(parsed_filter)

        return self
748830
def merged_params(*params)
      params.reduce(default_params) do |merged, params|
        merged.merge(params)
      end
    end
700506
def merge_model_instances(self, primary_object, alias_objects):
        
        generic_fields = get_generic_fields()

        # get related fields
        related_fields = list(filter(
            lambda x: x.is_relation is True,
            primary_object._meta.get_fields()))

        many_to_many_fields = list(filter(
            lambda x: x.many_to_many is True, related_fields))

        related_fields = list(filter(
            lambda x: x.many_to_many is False, related_fields))

        # Loop through all alias objects and migrate their references to the
        # primary object
        deleted_objects = []
        deleted_objects_count = 0
        for alias_object in alias_objects:
            # Migrate all foreign key references from alias object to primary
            # object.
            for many_to_many_field in many_to_many_fields:
                alias_varname = many_to_many_field.name
                related_objects = getattr(alias_object, alias_varname)
                for obj in related_objects.all():
                    try:
                        # Handle regular M2M relationships.
                        getattr(alias_object, alias_varname).remove(obj)
                        getattr(primary_object, alias_varname).add(obj)
                    except AttributeError:
                        # Handle M2M relationships with a 'through' model.
                        # This does not delete the 'through model.
                        # TODO: Allow the user to delete a duplicate 'through' model.
                        through_model = getattr(alias_object, alias_varname).through
                        kwargs = {
                            many_to_many_field.m2m_reverse_field_name(): obj,
                            many_to_many_field.m2m_field_name(): alias_object,
                        }
                        through_model_instances = through_model.objects.filter(**kwargs)
                        for instance in through_model_instances:
                            # Re-attach the through model to the primary_object
                            setattr(
                                instance,
                                many_to_many_field.m2m_field_name(),
                                primary_object)
                            instance.save()
                            # TODO: Here, try to delete duplicate instances that are
                            # disallowed by a unique_together constraint

            for related_field in related_fields:
                if related_field.one_to_many:
                    alias_varname = related_field.get_accessor_name()
                    related_objects = getattr(alias_object, alias_varname)
                    for obj in related_objects.all():
                        field_name = related_field.field.name
                        setattr(obj, field_name, primary_object)
                        obj.save()
                elif related_field.one_to_one or related_field.many_to_one:
                    alias_varname = related_field.name
                    related_object = getattr(alias_object, alias_varname)
                    primary_related_object = getattr(primary_object, alias_varname)
                    if primary_related_object is None:
                        setattr(primary_object, alias_varname, related_object)
                        primary_object.save()
                    elif related_field.one_to_one:
                        self.stdout.write("Deleted {} with id {}\n".format(
                            related_object, related_object.id))
                        related_object.delete()

            for field in generic_fields:
                filter_kwargs = {}
                filter_kwargs[field.fk_field] = alias_object._get_pk_val()
                filter_kwargs[field.ct_field] = field.get_content_type(alias_object)
                related_objects = field.model.objects.filter(**filter_kwargs)
                for generic_related_object in related_objects:
                    setattr(generic_related_object, field.name, primary_object)
                    generic_related_object.save()

            if alias_object.id:
                deleted_objects += [alias_object]
                self.stdout.write("Deleted {} with id {}\n".format(
                    alias_object, alias_object.id))
                alias_object.delete()
                deleted_objects_count += 1

        return primary_object, deleted_objects, deleted_objects_count