elixir - Ecto: how to define variable default field values in schema? -
in ecto, can give fields in schema default value specifying them field :name, default: "john"
. in docs, stated default stored @ compile-time, , things date.now
or uuid.generate
not work.
my question is: how create these variable defaults? 1 'just set value after creating struct'. however, when working virtual fields, not possible. when use e. g. repo.all(mymodel)
or other querying-commands, virtual fields set default fixed value.
how can create variable schema field defaults?
it not possible. ecto defines struct , elixir structs expanded @ compile time.
you can around explicitly having function produce struct default values or in changeset function via put_change
, similar.
Comments
Post a Comment