# ROM::Repository::Root purpose and usage

**URL:** <https://discourse.rom-rb.org/t/rom-root-purpose-and-usage/570>\
**Category:** Architecture Design\
**Created:** [November 22, 2022, 7:03pm UTC](https://discourse.rom-rb.org/t/rom-root-purpose-and-usage/570 "2022-11-22T19:03:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![alassek](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/alassek/32/260_2.png) [@alassek](https://discourse.rom-rb.org/u/alassek)\
**Post date:** [November 22, 2022, 8:25pm UTC](https://discourse.rom-rb.org/t/rom-root-purpose-and-usage/570/2 "2022-11-22T20:25:20Z")

</div>

Here’s @solnic’s [brief explanation](https://discourse.rom-rb.org/t/difference-between-repositories-and-relations/317/8) of where this came from.

Essentially, given that you have a `UserRepo` that inherits `ROM::Repository[:users]`, this means that `UserRepo#root` will be aliased to `users`. That’s basically all there is to it.

For instance, here’s something I do in my app.

```ruby
module Entities; end

class Repository < ROM::Repository::Root
  include Deps[container: "persistence.rom"]

  struct_namespace Entities

  def find(id) = root.by_pk(id).one
  def find_by(...) = root.where(...).one
end

```

That simple alias trick means I am able to write `find` and `find_by` once and use them with all repos.

---

_[View the full topic](https://discourse.rom-rb.org/t/rom-root-purpose-and-usage/570)._
