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)

  dataset do |r|
          where(type: "bar")

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)

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")


This does sound like a nice new feature. I just reported it as an issue:


Thanks @solnic :smile: