Forum: Ruby on Rails Searching multiple tables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jables (Guest)
on 2008-11-10 04:30
(Received via mailing list)
Hey,
  I have three tables/models - stories, pictures, videos.  I want to
be able to search all of these at once to find entries within a date
range.  Currently I am searching each one and pushing the results onto
an array which I paginate and display.  This doesn't work correctly
because it doesn't sort correctly and seems like a poor solution.

Additionally it would be helpful to be able to sort a date range and
if that fails to find the 10 most recently added entries.  This seems
like a simple find but I'm not sure exactly how to do it.

Thanks for any help.
JB
Jean-Marc (M2i3.com) (Guest)
on 2008-11-18 21:55
(Received via mailing list)
Hi Jables,

There are no magic solution for what you're trying to do.

What you can do is search each model and use a 4th model as the search
result.... using that search result model to paginate and display your
page.

This way you should be able to sort in different fashion as made the
query much more efficient.

One question I have for you is how do you trigger the search?

Regards,

Jean-Marc
http://m2i3.com
This topic is locked and can not be replied to.