3 ms·
> Each “key type” in a map type is either required or optional. I wonder how that will work with Ecto schemas, or if it will work at all. Ecto Schemas do not s
by fndex 3y ago
> Each “key type” in a map type is either required or optional.
I wonder how that will work with Ecto schemas, or if it will work at all. Ecto Schemas do not specify required/optional keys, the Changesets do. But Changesets only exists in runtime. Loosing the ability to reuse the schema and have required/optional keys defined on the changesets would be a huge step back in my opinion, but pretty much all the type systems I know work that way.
- josevalim 3y agoThe schema struct itself has all keys as required (the keys are always present). The map you receive on your changeset has all keys as optional because they can be missing (which we convert into a changeset error if the field is validated as required).
- deleted 3y ago[deleted]
- fndex 3y agoBut how will it deal with nulls? For example, let's imagine I have a user schema. This schema has 3 fields, username, is_admin and admin_level. I can guarantee using changesets that when is_admin is true, admin_level must be non null. When is_admin is false, it can be null. admin_level would be always treated as nullable by the type system?
- josevalim 3y agoThe type system _may_ allow the type of a field to be based on the value of another field. I will investigate and, if possible, we would have to figure out a syntax that makes this possible to express.