ColumnScope Plugin version 1.0 released! * <http://github.com/boof/column_scope/> ColumnScope lets you select specified values from your DB into a model or an array without doing :select => SQL_FRAGMENT and map! {|r|r.foo} all the time. This plugin extends ActiveRecord::Base and mixes in named scopes. ColumnScope is a subclass of ActiveRecord::NamedScope::Scope so it can be chained with named scopes. Assume we have a Page(id:integer, path:string, title:string, body:text, timestamps) model and we have a page listing, there is no need to load the whole body for every page. Maybe we need only the path and title: Page.selects(:path, :title).values.all(:order => ''id'') # => [[''/ foo'', ''Foo''], [''/bar'', ''Bar''], ...] Further we can chain it with named scopes: Page.published.selects(:path, :title).values.all(:order => ''id'') # => [[''/foo'', ''Foo''], [''/baz'', ''Baz''], ...] # or using a shortcut Page.published.select_all(:path__title, :order => ''id'') # => [[''/ foo'', ''Foo''], [''/baz'', ''Baz''], ...] When this page is shown maybe we don''t need the path and id anymore, but the instance of the model: Page.published.rejects(:id, :path).find params[:id] # => <Page title="Foo" ...> -- Cheers Florian Aßmann --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---