My module looks like this:
defmodule Realtime.ListItem do
use Ecto.Schema
import Ecto
import Ecto.Changeset
import Ecto.Query, only: [from: 1, from: 2]
import Ecto.Query, only: [where: 2]
alias Realtime.Repo
alias Realtime.{Board, Card, List, ListItem}
schema “list_items” do
#…
field :sort_order, :integer
timestamps()
end
I am trying to create a simple function that will return the largest value of the property ‘sort_order’.
def find_max_sort_order(id) do
query = from(q in ListItem, where: q.id == ^id, order_by: [desc: q.sort_order], limit: 1)
Repo.all(query)
end
I am getting this error when trying to start phoenix up:
Compiling 4 files (.ex)
warning: variable “q” does not exist and is being expanded to “q()”, please use parentheses to remove the ambiguity or change the variable name
lib/realtime/models/list_item.ex:32
What am I doing wrong? Am I missing an import?
I simply want to return a single record, which has the maximum value of sort_order.