Support casting to atom from strings#7
Open
cheerfulstoic wants to merge 2 commits intomatthieupinte:masterfrom
Open
Support casting to atom from strings#7cheerfulstoic wants to merge 2 commits intomatthieupinte:masterfrom
cheerfulstoic wants to merge 2 commits intomatthieupinte:masterfrom
Conversation
Author
|
I realize this may seem picky for such a small library, but I imagine this being a prime example that people might look at when trying to figure out how Ecto types work. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ecto types can be so hard for me to wrap my head around sometimes, but I'm pretty sure this is right 😅
Here's an example from the docs with comments that I think are really helpful (I think they might be relatively new):
https://hexdocs.pm/ecto/Ecto.Type.html#module-example
But basically,
dumptakes what's on the Ecto schema struct and turns it into the database format. Socastis to take potentially supported values (e.g. in forms) and turn them into the data type that's expected to be on the Ecto schema struct. Basicallyloadwhile is loading from the DB,castis kind of like "loading" from the outside world, and thus potentially needs to support different types of data.In that example in the docs, there should always be a
%URI{}on the schema struct. Socasttakes strings and%URI{}values and assigns them (I could imagine it also taking maps with the URL parts, depending on what you wanted to do).