themarlzy
Assistance with Ecto, embedded and tables
Alchemists,
I’m pulling my hair out and thought I would come to this awesome community for assistance.
I’ve created a map (structs) which looks like the following:
%Trace{attributes: [%Attribute{key: "RequestedAmount",
type: "float", value: "20000.0"}, ...],
events: [%Event{attributes: [%Attribute{key: "AnotherKey"
, type: "string", value: "hello!"}
]
},
...]
}
I’m wanting to persist this to my PostgreSQL database. I’ve come up with the following schema:
defmodule XesParser.Trace do
use Ecto.Schema
schema "traces" do
embeds_many :attributes, Attribute
embeds_many :events, Event
end
end
defmodule XesParser.Attribute do
use Ecto.Schema
schema "attributes" do
field :type
field :key
field :value
end
end
defmodule XesParser.Event do
use Ecto.Schema
schema "events" do
embeds_many :attributes, Attribute
end
end
I have two questions:
- What table(s) should I create in the migration?
- How do I insert this into the database, once the migration is done? I’m guessing something like:
trace = Repo.insert!(%Trace{})
changeset = Ecto.Changeset.change(trace)
changeset = Ecto.Changeset.put_embed(changeset, example.attributes, :attributes)
changeset = Ecto.Changeset.put_embed(changeset, example.events, :attributes)
where the above is example, however, how do you manage the fact that events have attributes?
Any assistance would be wildly appreciated…
M
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
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
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
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
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
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
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
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
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









