I'm pretty confused by that. How does will_paginate know which tables to join on? Every row in the comments table could be associated with a different kind of commentable. Unless I'm missing something, there's no way that select can be done in one query. Example: Comments Table ID commentable_type 1 Post 2 User 3 Clipping 4 User 5 Post
How can you eagerly load the commentable association? You'd have to do a join on posts, users, and clippings, without knowing in advance which tables you need to join on. The only thing I can think of is that will_paginate grabs the result set and loops through it and loads the association for each row. Anybody else know how this is working? On Mon, Oct 5, 2009 at 10:04 AM, moritz <[email protected]> wrote: > > will_paginate seems to be handling it: > > >> Comment.paginate(:all, :include => :commentable, :page => 1, :per_page > => 2) > Comment Load (0.4ms) SELECT * FROM "comments" LIMIT 2 OFFSET 0 > Article Load (0.2ms) SELECT * FROM "articles" WHERE > ("articles"."id" = 1) > Photo Load (0.3ms) SELECT * FROM "photos" WHERE ("photos"."id" = > 1) > > >> Comment.paginate(:all, :include => :commentable, :page => 2, :per_page > => 2) > Comment Load (0.4ms) SELECT * FROM "comments" LIMIT 2 OFFSET 2 > Article Load (0.8ms) SELECT * FROM "articles" WHERE > ("articles"."id" IN (1,2)) > > compared with: > >> Comment.paginate(:all, :page => 1, :per_page => 2) > Comment Load (0.4ms) SELECT * FROM "comments" LIMIT 2 OFFSET 0 > SQL (0.2ms) SELECT count(*) AS count_all FROM "comments" > > This definitely reduces the amount of database queries issued in a > longer list. > > On Oct 5, 7:50 am, Bruno Bornsztein <[email protected]> > wrote: > > Hmmm.... strange that will_paginate doesn't raise an error. It should > *not* be > > able to eager load a polymorphic association like commentable. The > problem > > is that with a polymorphic association, the commentable could be from any > > number of tables (it could be a User, a Post, a Clipping, etc.), so eager > > loading won't work because Rails doesn't know which tables to join on > ahead > > of time. > > I suspect something else is going on here, like maybe will_paginate just > > disregards the :include parameter when it's polymorphic (or something). > > > > I'm not strongly opposed to using will_paginate if the integration is > clean > > and upgrading is smooth, but I don't see any great benefit in moving to > it > > (maybe someone can convince me). > > > > Thanks, > > Bruno > > > > On Sun, Oct 4, 2009 at 10:35 PM, moritz <[email protected]> wrote: > > > > > I'm getting an ActiveRecord::EagerLoadPolymorphicError with > > > paginating_find when I include an :include => :commentable parameter > > > in the call. This doesn't happen when I use will_paginate instead. > > > > > After testing and confirming this outside of CE, I am wondering if > > > it's possible and of interest to the community to replace > > > paginating_find with will_paginate within CE. What would be the > > > pitfalls? Any feedback is very welcome. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CommunityEngine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/communityengine?hl=en -~----------~----~----~----~------~----~------~--~---
