, . JSONB, embeds_many, . (http://blog.plataformatec.com.br/2015/08/working-with-ecto-associations-and-embeds/), , .
, JSONB,
{
"name":"Something",
"address":"123 Fake St"
}
[
{
"field":"name",
"value":"Something"
},
{
"field":"address",
"value":"123 Fake St"
},
]
, , ( Ecto , ).
. :
defmodule UserManager.CustomField do
use Ecto.Model
embedded_schema do
field :field
field :value
end
@required_fields ~w(field value)
@optional_fields ~w()
@doc """
Creates a changeset based on the `model` and `params`.
If no params are provided, an invalid changeset is returned
with no validation performed.
"""
def changeset(model, params \\ :empty) do
model |> cast(params, @required_fields, @optional_fields)
end
end
defmodule UserManager.Client do
schema "clients" do
embeds_many :custom_fields, UserManager.CustomField
end
end