Skip to content

Instantly share code, notes, and snippets.

@noahhendrix
Created July 12, 2010 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahhendrix/472702 to your computer and use it in GitHub Desktop.
Save noahhendrix/472702 to your computer and use it in GitHub Desktop.
Sample code to demonstrate ideal behavior in MetaSearch
s = Activity.search
# => #<MetaSearch::Builder:0x000001053b4588 @relation=[#<Activity id: 1...
s.date_gteq = Date.yesterday
# => Sun, 11 Jul 2010
s.to_sql
# => "SELECT \"activities\".* FROM \"activities\" WHERE (\"activities\".\"date\" >= '2010-07-11')"
s.date_gteq = s.date_gteq.beginning_of_week
# => Mon, 05 Jul 2010
s.to_sql
# => "SELECT \"activities\".* FROM \"activities\" WHERE (\"activities\".\"date\" >= '2010-07-11') AND (\"activities\".\"date\" >= '2010-07-05')"
#In the last SQL statement it obviously doesn't work as I expect because it appends the date clause twice, and the latest one is the only one that takes affect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment