Sha256: 4ecd684116b0c384c2918ee57e23ba888e744de812bc740558355a87a0417e25

Contents?: true

Size: 1.26 KB

Versions: 28

Compression:

Stored size: 1.26 KB

Contents

module Sequel
  module Plugins
    # The table_select plugin changes the default selection for a
    # model dataset from <tt>*</tt> to <tt>table.*</tt>.
    # This makes it so that if you join the model's dataset to
    # other tables, columns in the other tables do not appear
    # in the result sets (and possibly overwrite columns in the
    # current model with the same name).
    #
    # Usage:
    #
    #   # Make all model subclasses select table.*
    #   Sequel::Model.plugin :table_select
    #
    #   # Make the Album class select albums.*
    #   Album.plugin :table_select
    module TableSelect
      # Modify the current model's dataset selection, if the model
      # has a dataset.
      def self.configure(model)
        model.instance_eval do
          self.dataset = dataset if @dataset
        end
      end

      module ClassMethods
        private

        # If the underlying dataset selects from a single table and
        # has no explicit selection, select table.* from that table.
        def convert_input_dataset(ds)
          ds = super
          if !ds.opts[:select] && (from = ds.opts[:from]) && from.length == 1 && !ds.opts[:join]
            ds = ds.select_all(ds.first_source)
          end
          ds
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

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