property value as Union type

This commit is contained in:
Moritz 2025-05-28 18:39:08 +02:00
parent e3779a73ff
commit b849cfa3df
Signed by: moritz
GPG key ID: 1020A035E5DD0824
10 changed files with 87 additions and 34 deletions

View file

@ -16,8 +16,16 @@ defmodule Mv.Membership.Property do
attributes do
uuid_primary_key :id
attribute :value, :string,
description: "Speichert den Wert, Typ-Interpretation per property_type.typ"
attribute :value, :union,
constraints: [
storage: :type_and_value,
types: [
boolean: [type: :boolean],
date: [type: :date],
integer: [type: :integer],
string: [type: :string]
]
]
end
relationships do
@ -25,4 +33,8 @@ defmodule Mv.Membership.Property do
belongs_to :property_type, Mv.Membership.PropertyType
end
calculations do
calculate :value_to_string, :string, expr(value[:value] <> "")
end
end

View file

@ -10,7 +10,7 @@ defmodule Mv.Membership.PropertyType do
actions do
defaults [:create, :read, :update, :destroy]
default_accept [:name, :type, :description, :immutable, :required]
default_accept [:name, :value_type, :description, :immutable, :required]
end
attributes do
@ -18,7 +18,8 @@ defmodule Mv.Membership.PropertyType do
attribute :name, :string, allow_nil?: false, public?: true
attribute :type, :string,
attribute :value_type, :atom,
constraints: [one_of: [:string, :integer, :boolean, :date]],
allow_nil?: false,
description: "Definies the datatype `Property.value` is interpreted as"