Tom Conroy
Tom Conroy
We are certainly preloading before cast. The key thing is the `apply_changes` results in ecto structs with the new children, but without `ids` because they are yet to be persisted....
I see why it's confusing, maybe this illustrates more clearly? ```elixir struct = %MyStruct{ children: [%Child{ id: nil, nested_child_id: 123, nested_child: %Ecto.Association.NotLoaded{} }] } preloaded_struct = Repo.preload(struct, [children: :nested_child] preloaded_struct.children...
Yes I understand that, in our case the struct is created through the `apply_changes` function after `cast_assoc` (with new items not yet persisted) – I want to pass this struct...
I want to keep the existing behavior (only load `%Assocation.NotLoaded{}` data from the db) but allow already-loaded data to have `nil` ids without printing a warning
Sorry, I use "loaded" to mean more narrowly "a value is that not `Association.NotLoaded`" rather than implying it came from the db https://github.com/elixir-ecto/ecto/blob/2e66ee8ca7c4861d6f00771651d42329664d77ab/lib/ecto.ex#L575-L578
I mentioned our use-case in the original post > snapshotting values like "price" in an order item from product selections I can elaborate on what I mean: our `OrderItem` points...
@tfwright definitely related! Before arriving at `apply_changes` I had a lot of `get_field` and so on (that's what I mean by a parallel version that operates on changesets rather than...
That's accurate! That entity (the order item) has a changeset that casts the user's selections for the configuration, then we take the values from the configuration's associations to put calculated...
Well, the `cast_assoc` may create new nested assocs with their own missing `id`s. To be clear, this PR doesn't change any real behavior in ecto, only allows suppressing the warning...