If we have some attribute aliased in the relation and we want to use a custom dataset, we have to do something like the following:
class Foo < ROM::Relation[:sql]
schema(:foo, infer: true) do
attribute :nmb, Types::String.meta(alias: :number)
end
dataset do |r|
select(*r.schema.map(&:qualified)).
order(*r.schema.project(*r.schema.primary_key_names).qualified).
where(type: "bar")
end
end
This is very cumbersome. I guess we could define a default_dataset method in the relation class, so we could simply do:
dataset do |r|
r.default_dataset.where(type: :bar)
end
Well, I was to quick… dataset block context belongs to Sequel gem, so I guess that what would be needed is to wrap it a ROM class delegating to the first one and do something like this:
dataset do |r|
# here `self` is a kind of Sequel Dataset decorator
default_dataset(r).where(type: "bar")
end