Change default dataset configured in ROM
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.
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