-
-
Save cblavier/356e662fdbc7910cc4bc39737d7851c2 to your computer and use it in GitHub Desktop.
Ecto put_assoc with an array of ids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tags = for id <- [40, 41, 42] do | |
%Tag{id: id, __meta__: %Ecto.Schema.Metadata{source: "tags", state: :loaded}} | |
end | |
Book | |
|> Repo.get(1000) | |
|> Repo.preload(:tags) | |
|> Book.changeset() | |
|> Ecto.Changeset.put_assoc(:tags, tags) | |
|> Repo.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why does this work?