blacksmith icon indicating copy to clipboard operation
blacksmith copied to clipboard

embedded_schema support / best practises

Open casio opened this issue 10 years ago • 4 comments

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?

casio avatar Oct 28 '15 18:10 casio

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

batate avatar Oct 28 '15 19:10 batate

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

ericmj avatar Nov 01 '15 01:11 ericmj

Cool, thanks @ericmj - working nicely in my app, too!

Should we leave the ticket open, whatsoever?

casio avatar Nov 03 '15 11:11 casio

Yes, we are going to provide an out-of-box solution

Eric Meadows-Jönsson

ericmj avatar Nov 04 '15 01:11 ericmj