Conversation
|
|
||
| def cast(list) when is_list(list) do | ||
| path_is_correct? = Enum.all?(list, fn(path_id) -> is_integer(path_id) end) | ||
| path_is_correct? = Enum.all?(list, fn(path_id) -> (is_integer(path_id) || is_binary(path_id)) end) |
There was a problem hiding this comment.
Move condition check to the new line, it'll be easier to read. Plus, make it looks better.
Depending on id_type option provided in use, check for either uuid or regular. Create a private function for each. For uuid, please use an Ecto default functionality.
|
|
||
| test "fails with wrongs path" do | ||
| assert Path.cast([14, "ee", 45]) == :error | ||
| assert Path.cast([14, [:ok], 45]) == :error |
There was a problem hiding this comment.
"ee" should still fail - because it's not an uuid
|
|
||
| def cast(list) when is_list(list) do | ||
| path_is_correct? = Enum.all?(list, fn(path_id) -> is_integer(path_id) end) | ||
| path_is_correct? = Enum.all?(list, fn(path_id) -> (is_integer(path_id) || is_binary(path_id)) end) |
There was a problem hiding this comment.
Please write an option to use macro, something like
use EctoMaterializedPath,
id_type: :uuid # default is `:regular`
and add a few lines to the doc
There was a problem hiding this comment.
thx for the feedback, I like the way you want it to do. what I'm struggling (Elixir noob) is how to access the id_type passed to use from within the Path module.
Thought about adding a function to the base module, but then I don't know how to access the id_type outside of the macro.
There was a problem hiding this comment.
You have to figure out by yourself. I don't have a time right now :( Use SO/elixir forum to get it and write according to my feedback
When using UUID's as a table's primary key it currently fails because of the check if path values are integers.
Extended to check if path values are either integer or binaries.