I am attempting to update a existing records in my database using Repo.update:
def subscribe_email(conn, %{"email-address"=>email_address, "shop"=>shop}) do
current_record = Repo.all(%Oauth.EmailAddress{email_address: email_address, active: false, shop: shop, verified: :true})
current_record = Ecto.Changeset.change(current_record, active: :true)
case Repo.update current_record do
{:ok, struct} -> IO.puts "updated correctly."
{:error, changeset} -> IO.puts "did not update"
end
end
I have a model for %Oauth.EmailAddress:
defmodule Oauth.EmailAddress do
use Ecto.Model
schema "email_address" do
field :email_address, :string
field :active, :boolean
field :shop, :string
field :verified, :boolean
timestamps
end
end
When I hit subscribe_email(), an exception is raised:
** (Protocol.UndefinedError) protocol Ecto.Queryable not implemented for %Oauth.EmailAddress
I know that I need to implement to_query() from Ecto.Queryable. However, I do not know how to do this. I am not familiar with Protocols in Elixir, although I have read the official documentation, I have not used Protocols. Please explain how to implement to_query() for my struct.