Closed joshuataylor closed 7 years ago
Here's the workaround I ended up doing:
def process_has_many(struct, params, schema, field, key) do
case Map.has_key?(params, key) do
true ->
results = schema |> where([p], p.id in ^params[key]) |> Repo.all
struct |> Ecto.Changeset.put_assoc(field, results)
false ->
struct
end
end
And then in my changeset:
|> process_has_many(params, Post, :posts, "post_ids")
You will have to handle this yourself as you did above or some other way. ✔️
@alanpeabody is there any plan to support the JSON API spec for modifying relationships?
Not currently... It actually isn't a feature I have ever used.
So I have a schema with a has_many, and passing that information through with
relationships
in a JSON API Resource produces the following with ja_resource:Now this is fine, but is there a "standard" way to process this in a changeset, or do I have to write this myself in each schemas changeset?
We should also add this to the docs.