Bit of a weird situation here.

So I have a dataset that I want to be able to pass around everywhere 
treated normally, except that I have a `WHERE
` and `GROUP BY` I want to always apply to it before any rows are returned.

I can't just do `ds.group(:a, :b)` and pass that around, because any 
conditions or joins that would be called on it in the meantime would be 
applied in the wrong order.

So I basically want something similar to how `row_proc` works, except it's 
more of a `dataset_proc`.

It seems to me like the most straightforward way to accomplish this would 
be modifying `each`:

module Sequel
  class Dataset
    def with_dataset_proc(ds_proc)
      @opts[:dataset_proc] = ds_proc
    end

    alias_method :each, :_each

    def each
      @opts[:dataset_proc].call(self)._each
    end
  end
end

ds = ds.with_dataset_proc(Proc.new(|ds| ds.where(:x => 1).group(:a, :b))

Not sure if that's valid code above, but hopefully gets the idea across.

Is this a good way to go about it, or is there perhaps a more elegant 
solution, or something already existing that does the same thing?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/c6b5a80f-a68d-43bd-96df-405cd94113c0%40googlegroups.com.

Reply via email to