You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tried replacing Repo.set with Repo.mutate but same issue persists.
The text was updated successfully, but these errors were encountered:
goravbhootra
changed the title
Repo.mutate creates new node rather than updating existing node
Repo.set creates new node rather than updating existing node
Jul 4, 2020
To those who are looking for a solution, i.e. to update existing nodes in Dgraph with Ecto changesets:
Cast uid in your changeset.
Validate require uid in your changeset.
Force change uid in your changeset.
For example:
def update_changeset(%Struct{} = struct, attrs) do
struct
|> cast(attrs, [:uid])
|> validate_required([:uid])
|> force_change(:uid, struct.uid)
end
This will update an existing node in Dgraph based on the given uid.
Perhaps it's possible to indicate to Ecto that uid is a primary key so that uid is automatically added to Ecto.Changeset changes field, but I have not tested this.
Expected behaviour: Existing node should be updated
Actual behaviour: New node is created every time
version: 0.5.1
Same implementation was working fine with earlier version.
Implementation:
file
lib/lms/courses/course.ex
contains:and
lib/lms/courses.ex
contains:Following creates a new node rather than updating the existing node:
Course.changeset(attrs)
produces:and
data
key contains:Tried replacing
Repo.set
withRepo.mutate
but same issue persists.The text was updated successfully, but these errors were encountered: