Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define virtual attribute in Ecto model

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

like image 794
Jack Tang Avatar asked May 19 '16 06:05

Jack Tang


1 Answers

See at documentation:

:virtual - When true, the field is not persisted to the database.

Virtual fields exists temporary in the Schema and were not saved in the database. This is helpful for local processes and validations.

Example: An password confirmation field.

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

  timestamps
end

I hope this helps.

like image 141
Fabi755 Avatar answered Sep 17 '22 14:09

Fabi755