Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 443 Bytes

one_of.md

File metadata and controls

17 lines (13 loc) · 443 Bytes

One of

In case when you want to use different models depending on some condition you can use StoreModel.one_of method:

OneOfConfigurations = StoreModel.one_of do |json|
  json[:v] == 2 ? ConfigurationV2 : Configuration
end

class Product < ApplicationRecord
  attribute :configuration, OneOfConfigurations.to_type
end

class ProductList < ApplicationRecord
  attribute :configurations, OneOfConfigurations.to_array_type
end