travisf
Ecto 3 put_embed not accepting structs?
In upgrading from Ecto 2 to Ecto 3 I’m dealing with a failing test. If I use ExMachina build(:address) I’ll get an error trying to put_embed/3:
** (ArgumentError) unknown field `:__meta__` in %Orders.Schemas.InlineAddress{address: #Ecto.Association.NotLoaded<association :address is not loaded>, address_id: nil, city: nil, country_code: nil, delivery_instructions: nil, full_name: nil, id: nil, inserted_at: nil, line1: nil, line2: nil, override: nil, phone_number: nil, sap_id: nil, state_or_region: nil, type: nil, updated_at: nil, version: 1, zip_code: nil}
code: exec(order: order, send_email: send_email_mock, send_csv: send_csv_mock, csv: true)
stacktrace:
(ecto 3.6.2) lib/ecto/changeset.ex:1225: Ecto.Changeset.put_change/7
(stdlib 3.17) maps.erl:410: :maps.fold_1/3
(ecto 3.6.2) lib/ecto/changeset.ex:396: Ecto.Changeset.change/2
(ecto 3.6.2) lib/ecto/changeset/relation.ex:198: Ecto.Changeset.Relation.do_change/4
(ecto 3.6.2) lib/ecto/changeset/relation.ex:326: Ecto.Changeset.Relation.single_change/5
(ecto 3.6.2) lib/ecto/changeset/relation.ex:165: Ecto.Changeset.Relation.change/3
(ecto 3.6.2) lib/ecto/changeset.ex:1213: Ecto.Changeset.put_change/7
(ecto 3.6.2) lib/ecto/changeset.ex:1423: Ecto.Changeset.put_relation/5
(packsize_data 0.0.1) ...accounting/schemas/vendor_po.ex:52: Accounting.VendorPO.changeset/2
vendor_po.ex referenced looks like:
def changeset(%VendorPO{} = po, attrs) do
po
|> cast(attrs, ~w[customer_po_number]a)
|> put_embed_from_params(:shipping_address)
end
defp put_embed_from_params(changeset, key) do
put_embed(changeset, key, changeset.params["#{key}"])
end
Changing the test to params_for(:address) works. I don’t see anything in the Ecto docs that indicates something changed, to the contrary the documentation for put_assoc/3 states:
changesets or structs - when a changeset or struct is given, they are treated as the canonical data and the associated data currently stored in the association is ignored.
First Post!
dimitarvp
Nothing comes to mind but have you tried first updating only to Ecto 3.0 just to make sure the upgrade is as minimal as possible?
Popular in Discussions
Maybe some of you know that there was (is?) something like BERT-RPC which in short is simplified version of External Term Format (also kn...
New
Hi, I’ve created a new repository on GitHub to compare the fairness and real-time performance of schedulers in Erlang and Go. Feel free t...
New
Hello,
I am looking to more closely understand the advantages of the Repo.transact pattern and the quoted disadvantages of Ecto.Multi.
...
New
Bonfire is an open source framework for building modular federated digital spaces. It’s built entirely with Elixir, including LiveView (a...
New
I created a Forth processor in Elixir. This is my hobby project.
https://github.com/sasagawa888/Forth
New
I wonder if it’s possible to mimic a simple “class reopening”/inhertinace-based SEAM in Elixir to alter a module’s behaviour without edit...
New
This thread is dedicated to announcing updates to the Hologram documentation, as well as discussing any ideas for improvements and sugges...
New
Hi,
I’m wondering is it my thinking process or this is the norm among the Elixir developer for the use of Struct and accessor functions ...
New
Hey everyone,
I’ve been working with Elixir for over 5 years and I’m a big enthusiast of the language. However, when starting new projec...
New
At HCA Healthcare (500k employees and contractors), we’re currently experimenting with Elixir for both data integration (to handle parsin...
New
Other popular topics
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
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
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
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
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
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New







