Hello,
I am in process of learning elixir phoenix and ecto, so far I love it.
Though, I am having hard time combining Ecto.Type and :source field together and i am not even sure if that is possible.
Let’s assume the following simple schema:
schema "content_articles" do
field :title, :string
field :body, :string
field :formatted_body, :string, [source: :body ]
field :status, :string
timestamps()
end
Executing query with this schema, it outputs something like
SELECT c0."id", c0."title", c0."body", c0."body", c0."status", c0."inserted_at", c0."updated_at", c0."id" FROM "content_articles" AS c0 WHERE (c0."id" = $1)
So body column is referenced twice. So far so good.
I am now trying to replace :string with MyCustomType which implements the Ecto.Type for the formatted_body field:
#aliases here
schema "content_articles" do
field :title, :string
field :body, :string
field :formatted_body, MyCustomType , [source: :body ]
field :status, :string
timestamps()
end
gives the following error:
** (Postgrex.Error) ERROR 42703 (undefined_column): column c0.formatted_body does not exist
What am I missing? Should maybe map the formatted_body to body within the load callback?