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

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
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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics 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
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
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 42633 214
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement