Sha256: ffcfd938994761c38c10f11b5527bb6a93326cbe8a8b44b6036a12514d0bb5ab

Contents?: true

Size: 1.52 KB

Versions: 18

Compression:

Stored size: 1.52 KB

Contents

# The filter_having extension allows Dataset#filter, #and, #or
# and #exclude to operate on the HAVING clause if the dataset
# already has a HAVING clause, which was the historical behavior
# before Sequel 4.  It is only recommended to use this for
# backwards compatibility.
#
# You can load this extension into specific datasets:
#
#   ds = DB[:table]
#   ds = ds.extension(:filter_having)
#
# Or you can load it into all of a database's datasets, which
# is probably the desired behavior if you are using this extension:
#
#   DB.extension(:filter_having)

#
module Sequel
  module FilterHaving
    # Operate on HAVING clause if HAVING clause already present.
    def and(*cond, &block)
      if @opts[:having]
        having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def exclude(*cond, &block)
      if @opts[:having]
        exclude_having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def filter(*cond, &block)
      if @opts[:having]
        having(*cond, &block)
      else
        super
      end
    end

    # Operate on HAVING clause if HAVING clause already present.
    def or(*cond, &block)
      if having = @opts[:having]
        cond = cond.first if cond.size == 1
        clone(:having => SQL::BooleanExpression.new(:OR, having, filter_expr(cond, &block)))
      else
        super
      end
    end
  end

  Dataset.register_extension(:filter_having, FilterHaving)
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
sequel-4.30.0 lib/sequel/extensions/filter_having.rb
sequel-4.29.0 lib/sequel/extensions/filter_having.rb
sequel-4.28.0 lib/sequel/extensions/filter_having.rb
sequel-4.27.0 lib/sequel/extensions/filter_having.rb
sequel-4.26.0 lib/sequel/extensions/filter_having.rb
sequel-4.25.0 lib/sequel/extensions/filter_having.rb
sequel-4.24.0 lib/sequel/extensions/filter_having.rb
sequel-4.23.0 lib/sequel/extensions/filter_having.rb
sequel-4.22.0 lib/sequel/extensions/filter_having.rb
sequel-4.21.0 lib/sequel/extensions/filter_having.rb
sequel-4.20.0 lib/sequel/extensions/filter_having.rb
sequel-4.19.0 lib/sequel/extensions/filter_having.rb
sequel-4.18.0 lib/sequel/extensions/filter_having.rb
sequel-4.17.0 lib/sequel/extensions/filter_having.rb
sequel-4.16.0 lib/sequel/extensions/filter_having.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/sequel-4.15.0/lib/sequel/extensions/filter_having.rb
sequel-4.15.0 lib/sequel/extensions/filter_having.rb
sequel-4.14.0 lib/sequel/extensions/filter_having.rb