You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Presently, schema fields must be defined explicitly as part of schema classes. This means that in order to validate the data required to create Article records, we could rely on the following schema:
classArticleSchema < Marten::Schema
field :title, :string, max_size:255
field :content, :stringend
This works fine, but this is not ideal since we are essentially "repeating" some of the properties of the fields of the model for which we want to validate data (eg. title and content fields in this example).
In order to allow for DRY-er codebases, we could allow schema fields to easily include fields generated from model fields. This could work by leveraging a new #model class method that would require a model and a list of model fields for which schema fields should be generated:
classArticleSchema < Marten::Schema
model Article, fields: [:title, :body]
end
This change will involve ensuring that model fields can generate corresponding schema fields if this is applicable for their use case. Some model fields could decide to not implement a corresponding schema fields, and in this case, a dedicated exception should be raised.
The text was updated successfully, but these errors were encountered:
Description
Presently, schema fields must be defined explicitly as part of schema classes. This means that in order to validate the data required to create
Article
records, we could rely on the following schema:This works fine, but this is not ideal since we are essentially "repeating" some of the properties of the fields of the model for which we want to validate data (eg.
title
andcontent
fields in this example).In order to allow for DRY-er codebases, we could allow schema fields to easily include fields generated from model fields. This could work by leveraging a new
#model
class method that would require a model and a list of model fields for which schema fields should be generated:This change will involve ensuring that model fields can generate corresponding schema fields if this is applicable for their use case. Some model fields could decide to not implement a corresponding schema fields, and in this case, a dedicated exception should be raised.
The text was updated successfully, but these errors were encountered: