On Thu, Sep 24, 2020 at 8:31 AM jaso...@gmail.com <jason...@gmail.com>
wrote:

>
> We ran into some code today that did a a `first` without an `order`.  I
> can think of no situation where you don't include an order if you include
> first (unless you are absolutely sure there's only one row, for example
> reloading a row with eager data).
>
> I want to find a way to raise an error if a query has this condition.   Is
> there a good way to do something like this?
>

DB.extend_datasets do
  def first(*)
    raise "not ordered" unless opts[:order] && !opts[:order].empty?
    super
  end
end

I would expect this may break quite a bit.  It's fairly common to use
Dataset#first when you expect the dataset to reference a unique row, in
which case an order is not necessary.

Thanks,
Jeremy

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSScicSZw08k%3DXDnQXcjhTzd1AohcUyQBe7raHt-CZ%3DuyKw%40mail.gmail.com.

Reply via email to