Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Change default dataset configured in ROM #645

Open

Description

@jaypandya73

As ROM is providing way to adjust default dataset here: https://rom-rb.org/3.0/learn/sql/relations/

I'm trying to change default dataset(remove default ordering) in latest hanami application and it seems that changing dataset isn't available here: https://github.com/hanami/model/blob/1.3.x/lib/hanami/repository.rb

So can you guys help me to find a way to change this default dataset as ROM document suggests and I believe this will also help to configure other ROM changes as well when we use ROM through Hanami.

Main goal is to remove default ordering that ROM provides on primary key.

Activity

  1. sswander commented on Oct 23, 2021

    @sswander

    I am also interested in this. We are introducing soft deletion by adding something like a deleted_at column in the table. However, we have a lot of existing queries and aggregations such that going through existing repository methods one-by-one to add a where(deleted_at: nil) is not feasible.

    After digging through the docs and codebase, I am currently stuck at monkey patching the Repository's self.load! method. I'm wondering if there's a better way around this?

    class BookRepository < Hanami::Repository
      def self.load!
        super
    
        configuration.setup.relation_classes.each do |klass|
          # .root => :books. This is to skip other relations included as associations
          next unless klass.register_as == root 
    
          klass.dataset do
            where(Sequel[:books][:deleted_at] => nil) # overrides default dataset here
          end
        end
      end
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions