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
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?
2
Popular in Questions
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
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
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
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
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
Background
Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
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
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
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
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
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
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
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
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
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New







