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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -