Velychkanych

Velychkanych

need help, on how to do it returning updated fields ?

How can I return to Repo.update only those fields that have been updated so as not to return the entire structure.
example :

def changeset(struct, params) do
    struct
    |> cast(params, [:id, :title, :type, :description, :user_id, :workspaces_id, :inserted_at, :updated_at])
    |> validate_required([:id, :title, :description])
  end
def update_change(%{id: 240333852503965697, title: "title", description: "description"}) do

    params
        |> changeset(params)
        |> Repo.update()
  end

result return →

%Database.Resources.MyApp{
  deleted_at: nil,
  description: "description",
  id: 240333852503965697,
  inserted_at: ~U[2020-03-13 12:04:32Z],
  title: "title",
  updated_at: ~U[2020-03-13 12:59:05Z],
  user_id: "777f47cb-28af-4b87-a45a-a3368e151190",
  workspaces_id: "c9e32ee2-2620-4db7-ac3a-6c30ed5b0f87"
}

I need return only field have been updated
example :

%Database.Resources.MyApp{
  description: "description",
  id: 240333852503965697,
  title: "title",
  updated_at: ~U[2020-03-13 12:59:05Z],
}

Most Liked

al2o3cr

al2o3cr

The intent “return only some fields” doesn’t match up smoothly with “return a struct”, since structs always have all their declared fields. What’s your goal?

Last Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

To be clear, it isn’t re-fetching all fields. It’s just keeping the ones that were in memory and merging the ones that you specify via returning.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement