Scope Columns
ColumnScope to select only certain values from your DB. I often need only single attributes of an ActiveRecord instance. In the past I used something like select_values(SELECT_SQL) or find(:all, :select => SELECT_SQL_FRAGMENT).map! { |r| [r.title, r.teaser]} to conservativly get them. After some time I felt the redundant code tiring and wrote this tiny plugin on top of named scopes. Usage examples:
Article.selects(:title_and_teaser).with_author.all # => [<Article ...]
Product.ordered_by_name.select_all(:name_and_prize) # => [['Apple Pie', 3.80], ...]
You can find the source and more examples in my repository @ github.
Post a comment