How to define a virtual attribute in an ecto model

I'm not very clean about the virtual attribute in the Ecto model, is it only mapped to the query result?

+7
elixir phoenix-framework ecto
source share
1 answer

See the documentation :

:virtual - When true, the field is not stored in the database.

Virtual fields exist temporary in the Scheme and were not stored in the database. This is useful for local processes and checks.

Example: password confirmation field.

 schema "users" do field :username, :string field :password, :string field :password_confirmation, :string, virtual: true timestamps end 

Hope this helps.

+13
source share

All Articles