Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default dataset configured in ROM #645

Open
jaypandya73 opened this issue Jul 28, 2021 · 1 comment
Open

Change default dataset configured in ROM #645

jaypandya73 opened this issue Jul 28, 2021 · 1 comment

Comments

@jaypandya73
Copy link

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.

@sswander
Copy link

sswander commented Oct 23, 2021

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants