Hi I''m wondering if there''s a way I can gather data from multiple tables from the child table by using the paginate method? I would have done it using select_by_sql but I need it to paginate. My table structure is: Records is a child of Date and Account Date Account | | ^ ^ Records I want to be able to print a table using the Records controller that will display child records dependent on a specific date/account. So I need a condition from more than one table. Can anybody help? -- Posted via http://www.ruby-forum.com/.
I would assume you could use the :joins option of the paginate method to get the tables you want. I''m not sure I understand you data structure though. Do you have a Record object that has a date_id property that is a foreign key to Date.id and an account_id that is a foreign key to Account.id? So then I think this would do it: @record_pages, @records = paginate :records, :per_page => 10, :joins => ["dates","accounts"], :conditions => ["dates.id = ? and accounts.id = ? ", date_id, account_id] On 5/7/06, Doug Bromley <doug.bromley@gmail.com> wrote:> > Hi > > I''m wondering if there''s a way I can gather data from multiple tables > from the child table by using the paginate method? > > I would have done it using select_by_sql but I need it to paginate. > > My table structure is: > > Records is a child of Date and Account > > Date Account > | | > ^ ^ > Records > > I want to be able to print a table using the Records controller that > will display child records dependent on a specific date/account. So I > need a condition from more than one table. > > Can anybody help? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060508/da6e6655/attachment.html
Paul Barry wrote:> I would assume you could use the :joins option of the paginate method to > get > the tables you want. I''m not sure I understand you data structure > though. > Do you have a Record object that has a date_id property that is a > foreign > key to Date.id and an account_id that is a foreign key to Account.id? > So > then I think this would do it: > > @record_pages, @records = paginate :records, :per_page => 10, > :joins => ["dates","accounts"], > :conditions => ["dates.id = ? and accounts.id = ? ", date_id, > account_id]Fantastic. You''re an absolute star. That works great - thank you. -- Posted via http://www.ruby-forum.com/.
Doug Bromley <doug.bromley@...> writes:> > Hi > > I''m wondering if there''s a way I can gather data from multiple tables > from the child table by using the paginate method? >Hi Doug, did you get the solution for that? I''m with the same problem.
Doug Bromley <doug.bromley@...> writes:> > Hi > > I''m wondering if there''s a way I can gather data from multiple tables > from the child table by using the paginate method? >look up this link: http://tinyurl.com/juec9 I will try the :include option to try to solve it. That''s only work for rails 1.1. # Just 1 database query for all of this: authors = Author.find(:all, :include => [ { :posts => :comments }, :categorizations ]) authors[0].posts[0].comments[0].body # => "Rock on Rails!" authors[0].categorizations[0].name # => "Less software"