Friends, I’m going through a problem.
I’m not able to show the “phoenix” on the screen the values he finds.
Below I will detail how my files are, with the error.
What could it be?
def list_cdr do
query_list_cdr = from e in Ecdr,
select: [e.calldate, e.accountcode, e.amaflags, e.billsec, e.channel, e.clid, e.dcontext, e.disposition, e.dst, e.dstchannel, e.duration, e.lastapp, e.lastdata, e.src, e.uniqueid, e.userfield], limit: 1
Repo.all(query_list_cdr)
end
Controller:
def index(conn, _params) do
cdr = Structure.list_cdr()
render(conn, "index.html", cdr: cdr)
end
Yeah, now I see the problem, as I have the full trace…
ecdr.calldate (as ecdr is not a map) gets expanded to :erlang.apply(ecdr, :calldate, []), which can not work, as ecdr is not an atom as well.
As @jeremyjh said, you need to return something from the query, that supports struct syntax for field access, currently only a map with atom keys supports this syntax.
Sorry, its a map, it needs a %, I’ll edit my post. But @Nobbz is right you can also just select: e here, or leave out the select entirely as that is the default.
@jeremyjh probably had a typo and meant to select: %{...}. And I have not much knowledge about the query DSL, but for me it seems as if you want most, if not all, fields anyway.
I’m pretty sure ecto has some way to express the equivalent of select *…
Your query is perfectly legal, but it returns a list (array) of items, and when you do Repo.all(query_list_cdr) you get a list of lists. That’s why ecdr.calldate throws error because you can’t access list item like that. I think maybe you mixed up the syntax with another language.