That seems like a workable solution.

A subtle thing to remember is that only one of the queries needs to
include the current date. Something like...

current_time = Time.now
all_events = Event.all(:event_date.gte => current_time, :limit => 3) +
Event.all(:event_date.lt => current_time, :limit => 5)

If the query ran at the moment an event occurred you only want to find
it once. If you used ".lte" in the second query you'd find the event
twice. If you used ".gt" in the first and ".lt" in the second you'd
miss it entirely.

On Aug 3, 4:16 pm, Chris Webstar <[email protected]> wrote:
> Hey there!
>
> The model I'm operating on is an event planner. I want to build a
> query that returns the latest 3 past events, and the next 5 upcomming
> events.
>
> I've figured out I can do this chaining all() twice, once for past
> events with limit 3, and once for future events, limit 5, always
> sorted by date, older to newer.
>
> Since I'm relatively new to datamapper, I wanted to have some input on
> this, because it's the first time I have to build a query like this.
> How would you manage to do this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to