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
What do you think?