Skip to content
Ruby on Rails plugin based on NamedScope to select single columns without crippling your code. http://www.monkey-patch.me/column_scope
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib/active_record/named_scope
test
MIT-LICENSE
README.rdoc
Rakefile
init.rb

README.rdoc

ColumnScope

Selecting only specified columns can safe you resources and processing time.

I wrote this plugin because I do this all the time and I don't want to cripple my code anymore.

ColumnScope is build on top of NamedScope so it only works with Ruby on Rails 2.1+.

Examples:

Item.selects(:name).proxy_options[:select] # => '"items"."name"'

content = 'Foo Bar Baz'

Item.create :name => 'foo', :value => 1, :content => content
Item.create :name => 'bar', :value => 2, :content => content
Item.create :name => 'baz', :value => 3, :content => content

Item.selects(:name).values.all :order => 'id' # => %w[foo bar baz]

# use a shortcut to retrieve values of name and content distinct
Item.select_first :distinct_name__content # => ['foo', content]

# without shortcut
Item.selects(:name, :content).uniq!.values.first # => ['foo', content]

# reject named columns in scope :a_named_scope and select only the values
Item.a_named_scope.rejects(:content).values.all # => [[1, 'foo', 1], ...]

See test/column_scope_test.rb for more examples.

Install (rails):

$ script/plugin install git://github.com/boof/column_scope.git

# alternativly:
$ cd vendor/plugins
$ git clone git://github.com/boof/column_scope.git

Copyright © 2008 Florian Aßmann, released under the MIT license

Something went wrong with that request. Please try again.