ActiveRecord::Extensions 0.5.0 Released!
on March 14, 2007 @ 02:14 AM
ActiveRecord::Extensions 0.5.0 is released! This release includes support for querying against Time objects against ActiveRecord columns which are considered :datetime by ActiveRecord’s standards .
Code Example
To find all blog posts within the last week:
BlogPost.find( :all, :conditions=>{ :created_at_gt => Time.now-1.week } ) |
To find all posts within the last year:
BlogPost.find( :all, :conditions=>{ :created_at_gt => Time.now-1.year } ) |
To find all posts over a year old:
BlogPost.find( :all, :conditions=>{ :created_at_lt => Time.now-1.year} ) |
User.find( :all, :conditions=>{ :logged_in_at_gt => Time.now-15.minutes} ) |
Supported Suffix Modifiers
This particular query addition supports the following column name suffix modifiers (ie: the “_lt” in the “created_at_lt”).- _lt => less than
- _gt => greater than
- _lte => less than or equal to
- _gte => greater than or equal to
- _ne => not equal to
- _not => not equal to
- eq => equal to _(this is implied without a suffix present)
MySQL TIMESTAMP Disclaimer
This does not work on TIMESTAMP columns for MySQL due to an issue with the inconsistency of TIMESTAMP columns in varying versions of MySQL and due to the nature of server configurations which can alter the behavior of TIMESTAMP columns.
PostgreSQL Support Note
I recently switched to a Mac, I am compiling PostgreSQL 8.1 and 8.2 as I type this. As soon as I can test this functionality against PostgreSQL I will release an update with that support.
Download It Now!
- Rubyforge: http://rubyforge.org/frs/?group_id=2113


0 comments
Jump to comment form | comments rss [?]