2014-12-27 5 views
4

저는 Ecto와 Elixir를 처음 사용하기 때문에 설명 할 수없는 오류가 발생했습니다. 내 코드는 Ecto README의 예제와 같습니다. 여기수정 프로토콜 Ecto.Queryable 구현되지 않은 오류

체외 모델 및 쿼리 여기

defmodule Registration do 
    use Ecto.Model 

    schema "registrations" do 
    field :user_id, :string 
    field :created_at, :datetime, default: Ecto.DateTime.local 
    field :updated_at, :datetime, default: Ecto.DateTime.local 
    end 
end 

defmodule RegistrationQuery do 
    import Ecto.Query 

    def by_user(user_id) do 
    query = from r in Registration, 
      where: r.user_id == ^user_id, 
     select: r 
    Repo.all(query) 
    end 
end 

내 모듈은 I 쿼리 기능을

registrations = Repo.all RegistrationQuery.by_user("underwater") 

이를 호출하는 방법을 모두 정확히 체외 문서와 일치 보인다, 그리고 내가 할 수있는 다르게 말하는 것을 발견하지 못합니다. 하지만 다음 오류가 발생합니다.

protocol Ecto.Queryable not implemented for [%Ensalutilo.Registration{user_id: "underwater"}] 

답변

6

귀하의 by_user/1 기능은 이미 Repo.all를 호출, 그래서 당신은 나중에 registrations = Repo.all(...)를 호출 할 때, 당신은 당신이 오류 메시지에서 보는 바와 같이 목록입니다 인수 바와 같이, 제 1 Repo.all의 결과를 전달하고 있습니다!

Ecto.Queryable 프로토콜을 구현하는 모든 항목을 Repo.all에 전달할 수 있으므로이 오류 메시지가 나타납니다.

관련 문제