# Ecto usage patterns

**URL:** <https://forum.elixirforum.com/t/ecto-usage-patterns/34234>\
**Category:** Discussions\
**Tags:** ecto, database, dsl\
**Created:** [September 8, 2020, 7:56am UTC](https://forum.elixirforum.com/t/ecto-usage-patterns/34234 "2020-09-08T07:56:02Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![al2o3cr](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/32/3457_2.png) [@al2o3cr](https://forum.elixirforum.com/u/al2o3cr)\
**Post date:** [September 8, 2020, 7:00pm UTC](https://forum.elixirforum.com/t/ecto-usage-patterns/34234/10 "2020-09-08T19:00:15Z")

</div>

> [@achempion](#):
>
> I miss the ActiveRecord where you could write `User.last` or `User.find_by(email: "email").posts` .

It’s definitely possible to write these in comparably-short ways, once you’ve done `import Ecto.Query`:

```elixir
User |> order_by(desc: :id) |> limit(1) |> Repo.one()

```

and

```elixir
Repo.get_by(User, email: "email") |> Ecto.assoc(:posts) |> Repo.all()

```

These assume you have your schema and repo aliased in, but that isn’t required - full names will work just as well.

---

_[View the full topic](https://forum.elixirforum.com/t/ecto-usage-patterns/34234)._
