embedded_schema support / best practises
Was using Blacksmith today for the first time. Nice lib, thanks!
I'm trying to use an Ecto embedded_schema in Forge.register, which leads to warnings about embedded data having to be assigned via their own changeset in Ecto.
My workaround is to manually add said changesets, now, which might become tedious when working with embedded schemas a lot.
Is support for this in the works, or are there other, easier workarounds?
Carsten, Eric is working on some Ecto changes for our app, but they are still under way.
Eric? What do you think?
-bt
On Wed, Oct 28, 2015 at 1:42 PM, Carsten Kraus [email protected] wrote:
Was using Blacksmith today for the first time. Nice lib, thanks!
I'm trying to use an Ecto embedded_schema in Forge.register, which leads to warnings about embedded data having to be assigned via their own changeset in Ecto.
My workaround is to manually add said changesets, now, which might become tedious when working with embedded schemas a lot.
Is support for this in the works, or are there other, easier workarounds?
— Reply to this email directly or view it on GitHub https://github.com/batate/blacksmith/issues/17.
Bruce Tate | CTO | 512.772.4312
i__can__make__it__better_.com_ http://icanmakeitbetter.com
Innovation + Research. Made Simple
We are working on a 0.2.0 release that will better support Ecto. In our own app we have the following code in our blacksmith save config to persist embedded associations:
def save(struct) do
module = struct.__struct__
model = struct(struct.__struct__, [])
changes = Map.from_struct(struct) |> Map.take(module.__schema__(:fields))
changeset = Ecto.Changeset.change(model, changes)
MyRepo.insert!(changeset)
end
Cool, thanks @ericmj - working nicely in my app, too!
Should we leave the ticket open, whatsoever?
Yes, we are going to provide an out-of-box solution
Eric Meadows-Jönsson