-
Notifications
You must be signed in to change notification settings - Fork 0
tomafro/rails-activerecord-columnreader
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A very simple utility, for when you want to easily read only a single column from an ActiveRecord model. Usage: class Monster < ActiveRecord::Base column_reader :name column_reader :hairyness, :as => :hirsutenesses column_reader :dob scope :dangerous, :conditions => {:carnivorous => true} end At it's simplest, it returns the values of just the given column: Monster.names # => ['Graham', 'Mike', 'Fuzzly'] The default accessor is the column name pluralized, but using the :as option, another name can be chosen: Monster.hirsutenesses # => ['bald', 'very', 'very'] Scopes are respected: Monster.dangerous.names # => ['Fuzzly'] And columns are correctly type cast: Monster.dobs: # => [#<Date: 4886491/2,0,2299161>, #<Date: 2886491/2,0,2299161>, #<Date: 3886491/2,0,2299161>]
About
A simple column reader for ActiveRecord
Resources
Stars
Watchers
Forks
Packages 0
No packages published