If the record does not exist, I would expect this conditional to create it, but it does not.... nil is returned.
case Repo.get_by(User, %{email: "[email protected]"}) do
struct ->
struct
nil ->
params = Map.merge(%{email: "[email protected]"}, %{password: "password"})
Repo.insert!(User.changeset(User.__struct__, params))
end
# returns nil.... huwutt???
However, if I change the ordering of the condition, it works. What am I missing here?
case Repo.get_by(User, %{email: "[email protected]"}) do
nil ->
params = Map.merge(%{email: "[email protected]"}, %{password: "password"})
Repo.insert!(User.changeset(User.__struct__, params))
struct ->
struct
end
# returns a set of 24" pythons, brother.... huzah!
struct
will bind tonil
– Spermous