Created
October 13, 2024 17:05
-
-
Save thanos/8f5894a65e049c9257ea133bd817e5d9 to your computer and use it in GitHub Desktop.
A select merge example for populating a virtual field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Answer do | |
use Ecto.Schema | |
schema "answer" do | |
field :word, :string | |
field :length, :integer, virtual: true | |
end | |
end | |
Repo.insert(%Answer{word: "SWANS"}) | |
Repo.one( | |
from answer in Answer, | |
select_merge: %{length: fragment("length(word)")} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment