Search code examples
elixirphoenix-frameworkecto

Pipe chain should start with a raw value


I have the following action in my Phoenix app controller:

  def index(conn, params) do
    studios =
      if params["search"] do
        Studio.search(Studio, params["search"])
      else
        Studio
      end
      |> Repo.all
      |> Repo.preload(:address)

    render conn, studios: studios
  end

When my run mix credo it returns following warning:

┃ [F] → Pipe chain should start with a raw value.
┃       lib/tattoo_backend/web/controllers/api/v1/studio_controller.ex:21 #(TattooBackend.Web.API.V1.StudioController.index)

I've tried to refactor that but I didn't find solution that will makes credo happy. Any ideas how to solve this?


Solution

  • queryable = 
      if params["search"] do
        Studio.search(Studio, params["search"])
      else
        Studio
      end
    
    queryable
    |> Repo.all()
    |> Repo.preload(:address)