# Recommendation for searching with regards to timestamp & foreign key attributes

**URL:** <https://www.ruby-forum.com/t/recommendation-for-searching-with-regards-to-timestamp-foreign-key-attributes/186465>\
**Category:** Rails\
**Created:** [April 7, 2010, 3:00pm UTC](https://www.ruby-forum.com/t/recommendation-for-searching-with-regards-to-timestamp-foreign-key-attributes/186465 "2010-04-07T15:00:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [April 7, 2010, 3:00pm UTC](https://www.ruby-forum.com/t/recommendation-for-searching-with-regards-to-timestamp-foreign-key-attributes/186465/1 "2010-04-07T15:00:21Z")

</div>

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

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
