AnApprentice
AnApprentice

Reputation: 110960

Rails - Getting the last X records back from the current record?

In Rails I have a model message: id, content

I want to run a query that does something the along the lines of.

if the current @message.content, is equal to any @message.content that was created_at less than 10 mins from now, return true else return false.

How would I go about structing an activerecord lookup like that? Thanks

Upvotes: 0

Views: 210

Answers (1)

Staelen
Staelen

Reputation: 7841

you can try doing this

Message.exists?(["created_at >= ? and content = ?", @message.created_at.advance(:minutes => -10), @message.content])

more info here

Upvotes: 1

Related Questions