I’m trying to use this line of code to get the last 10 messages entered.
App.Repo.all(Message, limit: 10)
But this instead returns all of the messages instead of just 10. What am I doing wrong?
I’m using {:phoenix_ecto, "~> 3.2"}
and :ecto, "2.2.8"
.
2 Likes
Repo.all/2
doesn’t seem to have a :limit
option, so probably that.
Try this instead
import Ecto.Query
Message
|> limit(10)
|> App.Repo.all()
5 Likes
Thank you, I didn’t know that.
Update: It works Thank you again.
1 Like