Recommendation for searching with regards to timestamp & foreign key attributes

hi guys,

I need a recommendation for searching with regards to timestamp &
foreign key attributes. Sounds
a bit too much but here’s an example.

Suppose we have a “blog” object. It has many attributes such as

  • title

  • content

  • status_id

  • created_at

  • updated_at

    There are also “status” objects which have the following statuses,
    “new”, “edit”,“published”,“archived”.
    That’s why the “blog” object has a foreign key, “status_id”.

Now, suppose I want to search for all blog objects that have been
created in the past 24 hours.
I would do

new_blogs = Blog.all(:conditions => { :created_at => (Time.now -
24.hours) … (Time.now) } )

Tested and that works just fine.

Suppose I would like to get all blog entries which are not of the
status of ‘published’ or ‘archived’.
I would just make use of searchlogic in the following way:

new_blog_entries = Blog.searchlogic(:status_name_does_not_equal_all
=> ([‘published’, ‘archived’]) )
OR
new_blog_entries = Blog.status_name_does_not_equal_any([‘published’,
‘archived’])

Question:

Suppose I now want to get blog entries which

  1. have been created within the last 24 hours
  2. have a status other than published and archived.

Any recommendations for doing this?

I couldn’t quite work out how to specify the status (as it’s a foreign
key) to the Blog model in the “:conditions”
AND similarly, I could not quite work out how to specify the “created
within the last 24 hours” filter using searchlogic.

I tried “new_blog_entries =
Blog.status_name_does_not_equal_any([‘published’,
‘archived’])_and_created_at((Time.now - 24.hours) … (Time.now))” but
I got an ugly error of "
SyntaxError: (irb):42: syntax error, unexpected tIDENTIFIER, expecting
$end
…‘published’, ‘archived’])_and_created_at((Time.now - 24.hours) …
(Ti…
… ^
from /usr/local/bin/irb:12:in `’

"

Any ideas?
thanks