By default, when a StoreModel attribute is invalid, the parent model only reports that the attribute is invalid. The specific error messages (e.g., color can't be blank) remain nested within the StoreModel instance.
To surface the specific errors directly on the parent model, use the merge_errors: true option in the validates call.
If you are using an array type (via .to_array_type), use merge_array_errors: true to merge errors from elements within the array. For array types, errors are prefixed with their index (e.g., [0]).
Note for Rails >= 6.1: Due to changes in Rails error internals, all merged errors will be placed under the parent attribute name (e.g., { configuration: ["Color can't be blank"] }) rather than the specific sub-attribute name.
# For a single StoreModel attribute
class Product < ApplicationRecord
attribute :configuration, Configuration.to_type
validates :configuration, store_model: { merge_errors: true }
end
# For an array of StoreModel attributes
class Product < ApplicationRecord
attribute :configurations, Configuration.to_array_type
validates :configurations, store_model: { merge_array_errors: true }
end