The Ecto library in Elixir apparently does not have a native find_or_create method comparable to Activerecord as of the time of this writing. However, here is a nifty method you can drop into one of your Ecto models to achieve this behavior.
In the following example, we want to find or create by the user’s email.
def find_or_create(user) do
query = from u in User,
where: u.email == ^user.email
Repo.one(query) || Repo.insert!(user)
Thanks to info found here!