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

But that generates all this queries: http://pastie.caboo.se/51507

Is there a way to generate a lot less queries?

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 =