Problem with using complex joins
Reported by BrianTheCoder | 2007-11-08 13:54:37 UTC
So I'm including some code from beast. On the post controller there's code using the paginate helper. Here's the code, or at least the relevant part.
@@query_options = { :per_page => 25, :select => 'posts.*, topics.title as topic_title', :joins => 'inner join topics on posts.topic_id = topics.id inner join sections on topics.section_id = sections.id', :order => 'posts.created_at desc' }
conditions = []
[:user_id, :section_id, :topic_id].each { |attr| conditions << Post.send(:sanitize_sql, ["posts.#{attr} = ?", params[attr]]) if params[attr] }
conditions = conditions.any? ? conditions.collect { |c| "(#{c})" }.join(' AND ') : nil
@post_pages, @posts = paginate(:posts, @@query_options.merge(:conditions => conditions))
I tried @posts = Post.paginate(@@query_options.merge(:page=> params[:page], :conditions => conditions))
Comments and changes to this ticket
-

Chris Wanstrath 2007-11-10 02:59:01 UTC
- Assigned user changed from Chris Wanstrath to Mislav
- State changed from new to open
-

Mislav 2007-12-19 16:51:47 UTC
I don't understand, what is the issue here? What is the error message? What SQL gets generated? What was expected? Thanks
-

BrianTheCoder 2007-12-19 18:28:46 UTC
I was trying to paginate a query on beast using will_paginate instead of paginator. The above code works for the formerly built in pagination for rails, but I could never get it to work with will_paginate. I'm at work not, but I'll post the errors that were generated when I get home. Also I could never get will_paginate to work with find_tagged_with, I end up using an ugly hack when I stripped out parts of the the tagged query and parsed it into will_paginate.
-

Mislav 2008-01-31 23:23:23 UTC
Hey Brian,
Can you confirm that this issue still exists? Can you paste me the code that doesn't work together with errors it makes? Read the formatting help above the comment box for instructions how to make a code block.
Thanks.
-

BrianTheCoder 2008-02-01 00:42:50 UTC
with the new version I've gotten it working with acts as taggable on steroids. Also rick demonstrated in beast the right way to do ti. Ticket can be closed.
-

Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Everyone's favorite Ruby library for pagination of practically anything!