Skip to content

Repo.load does not assign a value to virtual fields #4699

@curioustolearn

Description

@curioustolearn

Elixir version

Elixir 1.19.3 (compiled with Erlang/OTP 28)

Database and Version

PostgreSQL 16.11

Ecto Versions

ecto 3.13.5; ecto_sql 3.13.4

Database Adapter and Versions (postgrex, myxql, etc)

postgrex 0.21.1

Current behavior

I use raw sql query (using Ecto.Adapters.SQL.query) to query the postgres database and obtain data in which one of the columns is title alltags. I have a table in the database called "reports" and a schema file MyApp.Schemas.Report in which the alltags column is declared as a virtual field (please see below for the schema code).

When I try to map the query results to the Report schema defined below using the code:

                        fn row -> Repo.load(MyApp.Schemas.Report, Enum.zip(res.columns, row)) end)

then all columns other than alltags map fine, but the alltags column is nil (even though it is present in the results obtained from the raw query).

Thank you.

defmodule MyApp.Schemas.Report do
  use Ecto.Schema

  @primary_key {:id, :string, autogenerate: false}
  schema "reports" do
    field :author, :string
    field :reporttxt, {:array, :string}
    field :report_types, {:array, :map}

    # Virtual fields
    field :alltags, {:array, :string}, virtual: true


    timestamps(type: :utc_datetime)
  end
end

Expected behavior

I expect that the alltags column field will have the values returned by the raw database query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions