apotonick / disposable

Decorators on top of your ORM layer.
MIT License
171 stars 39 forks source link

Nilify true on a collection of strings #60

Closed zinkkrysty closed 6 years ago

zinkkrysty commented 7 years ago
class TradeInConfigurationForm < Disposable::Twin
  include Property::Hash

  property :options, field: :hash do
    collection :active_features, nilify: true
  end
end

config = EmbedConfigurations::TradeIn.find(id)
twin = TradeInConfigurationForm.new(config)
twin.options.active_features = ["lead_form", ""]

twin.options.active_features
#=> ["lead_form", ""]

I would expect the output to be ["lead_form"]

I'm actually using Reform but the example here is simplified.

This happens especially when using Rails and submitting collection_check_boxes through a form (it appends an empty string so that the update works when de-selecting all check boxes).

Is this not supported or is it a bug?

apotonick commented 7 years ago

The :nilify option doesn't exist in dry-types anymore - which is the engine we use for coercion. You have to provide a special :type, I'll look it up for you later today if you can't find it.

fran-worley commented 6 years ago

Rather than having this as a collection, you need to make it a property and set the type option to an appropriate dry-type constant. See http://dry-rb.org/gems/dry-types/array-with-member/

Now closing as this isn't actually an issue with disposable - get in touch via the slack/ gitter channels if you need more help