# 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:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jignesh](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@jignesh](https://discourse.rom-rb.org/u/jignesh)\
**Post date:** [November 22, 2022, 7:03pm UTC](https://discourse.rom-rb.org/t/rom-root-purpose-and-usage/570/1 "2022-11-22T19:03:15Z")

</div>

Hello,

Can anybody please help me in making understand the purpose of class `ROM::Repository::Root` and how to use it?

In the official documentation on rom-rb website under Repositories I couldn’t find any information related to that class.

And the API documentation at [Class: ROM::Repository::Root — Documentation for rom-rb/rom (main)](https://www.rubydoc.info/github/rom-rb/rom/ROM/Repository/Root) under Examples illustrates following:

```auto
class UserRepo < ROM::Repository[:users]
  commands :create, update: :by_pk, delete: :by_pk
end

```

It’s confusing that the Examples section for `ROM::Repository::Root` illustrates extending from `ROM::Repository`.

Also I posted a related question in my another post at [Using ROM 5.3.0 Repository with Hanami 2.0](https://discourse.rom-rb.org/t/using-rom-5-3-0-repository-with-hanami-2-0/569). I would highly appreciate if anybody can share inputs on it as well.

Thanks.

---

<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.
