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

Support Ecto Embed #112

Merged
merged 1 commit into from
Dec 18, 2020
Merged

Support Ecto Embed #112

merged 1 commit into from
Dec 18, 2020

Conversation

maennchen
Copy link
Contributor

@maennchen maennchen commented Oct 15, 2020

Replaces the functionality of embeds in #21, #30 and #60

For associations there's an easy point to hook in in the Serializer as well.

@izelnakri
Copy link
Owner

Hi @maennchen , thank you for your contribution! This seems to be a useful feature particularly because it makes db constraints easier to define on flat attributes/keys instead of having such keys inside the %Version{}.meta Map.

We should also document this feature well. Could you add the documentation to the README.md, also would be helpful to add a description to this PR, and share an example where you needed this feature.

This PR will likely get merged, there is also one more PR in the pipeline that I need to review/merge first: #83 . So we might need to rebase and fix merge conflicts afterwards, fyi.

@maennchen
Copy link
Contributor Author

@izelnakri I'm not sure what exactly you want to document. Essentially "supports ecto embeds" says everything already.

An example can be found in the tests, I can't link the place where we use is ourselves since the source is closed at the moment.

@izelnakri
Copy link
Owner

izelnakri commented Nov 28, 2020

@maennchen If I understood correctly we could achieve what ecto embed does by storing the embedded model as json without types(types in elixir are not a first-class citizen anyways), not sure I would like to add this runtime complexity to the library. Could you give me some real-life examples where embed is useful?

@maennchen
Copy link
Contributor Author

@izelnakri embed is useful to have Ecto.Changeset to validate your data / build forms.

I hope you accept this change because this is required to have full ecto support.

@izelnakri
Copy link
Owner

izelnakri commented Nov 30, 2020

Thanks for your quick response. I think we at least need a test case which could demonstrate to me the usefullness of this feature fully. I checked the ecto documentation, after several years, it generally touches on advanced topics however certain parts are still missing for me to grasp all the features library does, and how they work in details. Nonetheless our aim is to test everything well and full so test cases will need to be written for this feature.

@maennchen
Copy link
Contributor Author

@izelnakri Look at the changes commit by commit btw. It makes more sense that way. If you prefer I can also split it up into multiple PRs.

@maennchen
Copy link
Contributor Author

@izelnakri Any update on this?

@izelnakri
Copy link
Owner

Im super busy currently, and these changes are complex/requires thoughtful reviews, Im sorry. I'll do another review this or next week.

lib/paper_trail.ex Outdated Show resolved Hide resolved
|> Map.new(fn {key, value} ->
case schema.__schema__(:embed, key) do
%Ecto.Embedded{cardinality: :one} -> {key, serialize_model_changes(value)}
%Ecto.Embedded{cardinality: :many} -> {key, Enum.map(value, &serialize_model_changes/1)}
Copy link
Owner

@izelnakri izelnakri Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently trying to understand this line. Could you explain this further @maennchen , are these the only cases the code can ever hit? is there a _ -> _ case as well that allows certain keys to be ignored? or do they get ignored during embed_keys or maps with normal fields hit this %Ecto.Embedded{cardinality: :one} -> {key, serialize_model_changes(value)} per each/every key? Generally its a nice PR, but would have helped if we also published the changes in few PRs as I see few changes are bit unrelated. Regardless Im currently reading up on everything, thanks for the very interesting work! We should document this functionality in the README.md as well before merging anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's only two cases: embeds_one and embeds_many. Therefore no catch-all is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's four commits in this PR on purpose. I can open them in as many PRs as you like. (The order is kind of important though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About documentation I don't think there's much to say. The library supports ectos features. The features are already documented at ecto.

What would you like me to mention in the README?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izelnakri I split the PR apart into #122, #123, #124

Copy link
Owner

@izelnakri izelnakri Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Merged the first two, I'll also merge the third one. Could you make github clean the diff for the embed changes afterwards? I'll try to review in the next 10 days. Thanks again for all the work!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izelnakri Sure, I'll rebase it as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izelnakri Rebased as well.

@izelnakri
Copy link
Owner

Fantastic implementation, took me a lot of time to figure it out/fully comprehend completely but loved it :) Also definitely an improvement upon the previous change ;) Merging and cutting a release now, well done!

@izelnakri izelnakri merged commit 11fd333 into izelnakri:master Dec 18, 2020
mayel pushed a commit to bonfire-networks/paper_trail that referenced this pull request Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants