-
Notifications
You must be signed in to change notification settings - Fork 93
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
Support Ecto Embed #112
Conversation
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 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. |
@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. |
@maennchen If I understood correctly we could achieve what ecto |
@izelnakri I hope you accept this change because this is required to have full |
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. |
df6fe81
to
a1e3838
Compare
@izelnakri I've basically rewritten this PR since rebasing was not feasable. The tests you're looking for should be here:
|
@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. |
@izelnakri Any update on this? |
Im super busy currently, and these changes are complex/requires thoughtful reviews, Im sorry. I'll do another review this or next week. |
|> 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)} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@izelnakri Rebased as well.
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! |
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.