You can add a function in the Articles.Post (or something like that) module which would return the ordered results.
The index action in the controller then becomes
def index(conn, _params) do
bydesc = Articles.Post.fetch_ordered(desc: :inserted_at) # or is it just Articles.fetch_ordered/1?
render(conn, "index.html", bydesc: bydesc)
end
The function in Articles.Post can be something like
def fetch_ordered(constraint) do
Post |> order_by(constraint) |> Repo.all()
end
The point of phoenix 1.3 is moving this kind of logic out of the web layer and into the domain layer, I guess. There are quite a few threads around here discussing it.
Ah! The reason for this, is that the functions like from, where, order_by, etc. are part of the Ecto.Query module. To use them, write import Ecto.Query somewhere in your module (or if you only want to use it in a single function, only in that function).
It might very well be the case that this was part of the modules that were automatically included in the Phoenix controller logic before, but no longer in 1.3. I am not 100% sure. In any case, that’s where you can find those functions :-).