Here's roughly the code I have:
class PlatformConfiguration < ActiveRecord::Base
has_encrypted :properties, type: Properties.to_type
end
class PlatformConfiguration
PROPERTIES_MODELS = {
'platform' => 'PlatformProperties'
}
Properties = StoreModel.one_of do |json|
const_get(PROPERTIES_MODELS.fetch(json[:platform_service], 'EmptyProperties'))
end
end
class PlatformConfiguration
class EmptyProperties
include StoreModel::Model
attribute :platform_service, :string
end
end
class PlatformConfiguration
class PlatformProperties
include StoreModel::Model
attribute :platform_service, :string
attribute :api_key, :string
end
end
I've verified that the types work correctly when manually casting values, however when I set values like platform_configuration.properties = {platform_service: 'platform', api_key: '12345'} && platform_configuration.save, properties.platform_service shows up correctly, but properties.api_key ends up showing up as an unknown attribute even though it's reporting the correct PlatformProperties type.
We're on:
- rails 8.1
- ruby 3.3.10
- store_model 4.3.0
- lockbox 1.4.1
Here's roughly the code I have:
I've verified that the types work correctly when manually casting values, however when I set values like
platform_configuration.properties = {platform_service: 'platform', api_key: '12345'} && platform_configuration.save,properties.platform_serviceshows up correctly, butproperties.api_keyends up showing up as an unknown attribute even though it's reporting the correct PlatformProperties type.We're on: