I’ve been playing around with Ecto recently, but I’m a little confused as to why the following works:
query = from u in "users",
select: u.firstname,
where: u.username == "tpunt"
And yet the following doesn’t work:
query = from u in "users",
where: u.username == "tpunt"
By removing the select
clause from the query, Ecto suddenly requires that we query from a model, rather than the table name (as a string).
The exact error message given is the following:
** (Ecto.QueryError) MySQL requires a model when using selector "u0" but only
the table "`users`" was given. Please specify a model or specify exactly which
fields from "u0" you desire in query:
from u in "users",
where: u.username == "tpunt",
select: u
Even the code example in the error message doesn’t work. The select
clause must specifically choose a column (any column) in order for it to work. Can anyone explain these semantics?
Thanks.