Hi
If you have users and posts
You can User.find(blah blah) and Post.find(blah blah) - in both cases the
relevant tables will be searched.
If you want to return users that have made posts in the last 10 minutes
(assuming posts have user_id)
User.find(:all, :conditions => [''posts.created_at >
?'',10.minutes.ago],
:include => ''posts])
You will only get the users who posted in the last 10 minutes.
If you have @abc and you want to search the table associated with the
records in @abc you can (assuming @abc is a collection of activerecord
objects) do
@abc.first.class.name.classify.constantize.find(blah blah)
What this will do is get the class, from one of the elements in the
collection. If @abc was a collection of users then @
abc.first.class.name.classify.constantize will be User. Before the
constantize it will be "User".
Anyway, thats about all I can say and probably all I should say - not really
an expert here :)
regards
ivor
On 9/7/07, Dhaval Parikh
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> hello frnds
>
> Suppose i have generated pages using scaffolding so in the list.rhtml it
> is creating something like <% for abc in @abc %> so here when i put
an
> if condition it will search from the abc db only but if suppose i want
> to search from another table then what should I do. can i write simple
> sql query which will fetch info from other table of the same db? or is
> there ne other way to do so.......pls reply.
>
> thanks
>
> dhaval parikh
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---