Skip to content

Additional filters cannot take the name into account #104

@saverio-kantox

Description

@saverio-kantox

The comment at https://github.com/cypriss/mutations/blob/master/lib/mutations/model_filter.rb#L5

# default is the attribute name.to_s.camelize.constantize.

indicates that the class of a model (if not given) is generated using the attribute name. But there is no way for the filter to know the name of the attribute, because it's never passed to the initializer:

# https://github.com/cypriss/mutations/blob/master/lib/mutations/hash_filter.rb#L8
@current_inputs[name.to_sym] = type_class.new(options, &block)

the name is never passed to the constructor, with two nasty consequences:

  1. There is no way to set the model class from the name of the attribute.
  2. The options in the filter initializer are always empty, so the class constraint always resolves to Object, making it totally useless.

update

the ModelFilter is treated very differently than the rest of filters, so this actually applies only to custom additional filters, not to the model filter itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions