Skip to content

Latest commit

 

History

History
20 lines (13 loc) · 712 Bytes

unknown_attributes.md

File metadata and controls

20 lines (13 loc) · 712 Bytes

Unknown attributes

Sometimes JSON structure changes and it contains more keys than attributes defined in your StoreModel::Model class. In such cases, "unknown" attributes can be found inside the #unknown_attributes hash:

class Configuration
  include StoreModel::Model

  attribute :color, :string
end

configuration = Configuration.to_type.cast_value(color: "red", archived: true)
configuration.unknown_attributes # => { "archived" => true }

# OR

configurations = Configuration.to_array_type.cast_value([{ color: "red", archived: true }, { color: "blue", archived: false }])
configurations.map { |config| config.unknown_attributes } # => [{ "archived" => true }, { "archived" => false }]