Hi, I have this code: for user in User.find(:all, :include => :declarations ) for declaration in user.declarations pay += declaration.share($my) if declaration.my? paid = declaration.amount end end end end But that generates all this queries: http://pastie.caboo.se/51507 Is there a way to generate a lot less queries? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
LeonB wrote:> Hi, > > I have this code: > > for user in User.find(:all, :include => :declarations ) > > for declaration in user.declarations > pay += declaration.share($my) > > if declaration.my? > paid = declaration.amount > end > end > end > end > > But that generates all this queries: http://pastie.caboo.se/51507 > > Is there a way to generate a lot less queries?You log there doesn''t have the SQL for the loading of the users. You have the proper :include options but it doesn''t appear to be working. What SQL is generated from the Users query? -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the reply. That''s this huge query: SELECT users."id" AS t0_r0, users."email" AS t0_r1, users."firstname" AS t0_r2, users."lastname" AS t0_r3, users."password" AS t0_r4, users."account_number" AS t0_r5, users."created_at" AS t0_r6, users."updated_at" AS t0_r7, declarations."id" AS t1_r0, declarations."user_id" AS t1_r1, declarations."amount" AS t1_r2, declarations."description" AS t1_r3, declarations."created_at" AS t1_r4, declarations."updated_at" AS t1_r5 FROM users LEFT OUTER JOIN declarations_payers ON (declarations_payers.user_id = users.id) LEFT OUTER JOIN declarations ON (declarations.id declarations_payers.declaration_id) On Apr 4, 12:54 am, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> LeonBwrote: > > Hi, > > > I have this code: > > > for user in User.find(:all, :include => :declarations ) > > > for declaration in user.declarations > > pay += declaration.share($my) > > > if declaration.my? > > paid = declaration.amount > > end > > end > > end > > end > > > But that generates all this queries:http://pastie.caboo.se/51507 > > > Is there a way to generate a lot less queries? > > You log there doesn''t have the SQL for the loading of the users. You > have the proper :include options but it doesn''t appear to be working. > What SQL is generated from the Users query? > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---