Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: support to_ecto(%Ecto.Changeset{}) and from_ecto(%Ecto.C… #395

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ defmodule AshPostgres.Repo do
Enum.map(value, &from_ecto/1)
end

def from_ecto(%Ecto.Changeset{} = changeset) do
Map.put(changeset, :data, from_ecto(changeset.data))
end

def from_ecto(%resource{} = record) do
if Spark.Dsl.is?(resource, Ash.Resource) do
empty = struct(resource)
Expand Down Expand Up @@ -204,6 +208,10 @@ defmodule AshPostgres.Repo do
Enum.map(value, &to_ecto/1)
end

def to_ecto(%Ecto.Changeset{} = changeset) do
Map.put(changeset, :data, to_ecto(changeset.data))
end

def to_ecto(%resource{} = record) do
if Spark.Dsl.is?(resource, Ash.Resource) do
resource
Expand Down
Loading