Aliases and custom dataset

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?

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

This does sound like a nice new feature. I just reported it as an issue: Make default dataset available within the dataset configuration block · Issue #515 · rom-rb/rom · GitHub.

Thanks @solnic :smile: