Endon.last
You're seeing just the function
last
, go back to Endon module for more information.
Specs
last(integer(), keyword()) :: [Ecto.Schema.t()] | Ecto.Schema.t() | nil
Get the last count
records.
If you ask for one thing (count
of 1),
you will get back the last record or nil
if none are found. If you ask for more
than one thing (count
> 1), you'll get back a list of 0 or more records.
If no order is defined it will order by primary key descending.
Options
:order_by
- By default, orders by primary key descending:conditions
- Limit results to those matching these conditions. Value can be anything accepted bywhere/2
(including aEcto.Query.t/0
).
Examples
# get the last 3 posts, will return a list
posts = Post.last(3)
# get the last post, will return one item
post = Post.last()
# get the last 3 posts by author id 1
posts = Post.last(3, conditions: [author_id: 1])