Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ecto.Changeset pattern match, fix data sent to mutate(). #70

Merged
merged 3 commits into from
May 14, 2020
Merged

Add Ecto.Changeset pattern match, fix data sent to mutate(). #70

merged 3 commits into from
May 14, 2020

Conversation

martinthenth
Copy link
Contributor

@martinthenth martinthenth commented May 2, 2020

The Ecto.Changeset, valid?: false pattern match allows people to use Ecto Changeset in Dlex like they would with Ecto. If the changeset is valid, data is mutated in Dgraph, else returns {:error, changeset}.

For example: changeset = Post.create_changeset(Post{}, params) with Repo.set(changeset)

Furthermore, inserting data via changesets resulted in error: no function clause matching in MyApp.Post.__schema__/2. It also added unwanted fields from Ecto Changeset like __meta__, id, and predicates from schema with nil values. This was because data = struct(type, Map.put(changes, :uid, uid)) created a struct over which encode_kv() couldn't pattern match.

Now, data is inserted as expected using the Ecto.Changeset changes field.

@emhagman
Copy link
Collaborator

emhagman commented May 4, 2020

@liveforeverx This looks good to me, just wanted you to double check

@emhagman
Copy link
Collaborator

emhagman commented May 4, 2020

@martinthenth Do you mind adding the two tests for the examples you used (valid versus invalid changeset) here https://github.com/liveforeverx/dlex/blob/master/test/dlex/repo_test.exs so we make sure we don't break this going forward. We currently only have a test for using Repo.set on a new model struct

@martinthenth
Copy link
Contributor Author

Sure, I added two tests for Repo.set() with valid and invalid Ecto Changeset.

@liveforeverx liveforeverx merged commit 97a131a into liveforeverx:master May 14, 2020
@liveforeverx
Copy link
Owner

Thanks, @martinthenth ! 💛 💚 💙

Thanks @emhagman for review!

@martinthenth martinthenth deleted the dev branch May 15, 2020 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants