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?

Where Next?

Popular in Questions Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement