script

script

Remove fields from nested struct

I have this struct of preload records.
I want to remove
__meta__ and Ecto.Association.NotLoaded from the main struct as well as from the nested array of preloaded records. To make it a simple map

  %Facility{
  __meta__: #Ecto.Schema.Metadata<:loaded, "facilities">,
  id: 4875,
  instance: #Ecto.Association.NotLoaded<association :instance is not loaded>,
  name: "Facility",
 units: [
%Unit{
  __meta__: #Ecto.Schema.Metadata<:loaded, "units">,
  facility: #Ecto.Association.NotLoaded<association :facility is not loaded>,
  facility_id: 4875,
  id: 1593,
  name: "Storage",
  rooms: #Ecto.Association.NotLoaded<association :rooms is not loaded>
},
%Unit{
  __meta__: #Ecto.Schema.Metadata<:loaded, "units">,
  cdc_location_class_id: nil,
  facility: #Ecto.Association.NotLoaded<association :facility is not loaded>,
  facility_id: 4875,
  id: 1594,
  name: "Storage unit",
  rooms: #Ecto.Association.NotLoaded<association :rooms is not loaded>
}
],
users: #Ecto.Association.NotLoaded<association :users is not loaded>
}

Is it possible?

Thanks

Marked As Solved

NobbZ

NobbZ

There is no difference in both, those are equivalent from elixirs point of view.

Keys in a map are without any ordering guarantees.

Also Liked

idi527

idi527

Is it possible?

Yes, try writing a recursive function.

idi527

idi527

These outputs are identical. Try comparing them with === if you are in doubt.

Where Next?

Popular in Questions Top

tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

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
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I fore...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement