User properties and schema.yml
This section contains information about a new feature: associating properties directly to a user via schema.yml
.
Problem
Currently in order to add a property to a User, you need to go through UserProfile. In simple scenarios, this seems unnecessary and increases the learning curve. For example, if you wanted to add a mandatory property date_of_birth
, you would need to create a UserProfileType like Default
, and then write a Form similar to:
...
resource: User
fields:
profiles:
validation: { presence: true }
default:
validation: { presence: true }
properties:
validation: { presence: true }
date_of_birth:
validation: { presence: true }
...
It does not look simple, despite being one of the basic use cases.
Solution
What we would like to introduce is something closer to:
...
resource: User
fields:
properties:
date_of_birth:
validation: { presence: true }
In order to implement this, we need a place to define properties
for User in app
. Hence at the same time, we would like to introduce a new configuration file schema.yml
. To be able to get most of it, you will also be able to define Model Schemas and User Profiles in it [hence deprecating the Model Schemas and User Profile Types directories]. The schema.yml
could look like this:
user:
profiles:
seller:
company_name:
type: string
properties:
date_of_birth:
type: date
car:
properties:
engine:
type: string
Please note, that there are differences between defining properties in schema.yml
and in model_schemas/user_profile_types
. Instead of an array for properties, we will use a hash. It is a better data structure, because we want properties to be unique.