#149 ✓resolved

Problem with using complex joins

Reported by BrianTheCoder | November 8th, 2007 @ 01:54 PM

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

    Chris Wanstrath November 10th, 2007 @ 02:59 AM

    • Assigned user changed from “Chris Wanstrath” to “Mislav”
    • State changed from “new” to “open”
  • Mislav

    Mislav December 19th, 2007 @ 04:51 PM

    I don't understand, what is the issue here? What is the error message? What SQL gets generated? What was expected? Thanks

  • BrianTheCoder

    BrianTheCoder December 19th, 2007 @ 06:28 PM

    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

    Mislav January 31st, 2008 @ 11:23 PM

    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.


  • BrianTheCoder

    BrianTheCoder February 1st, 2008 @ 12:42 AM

    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.

  • Mislav

    Mislav February 23rd, 2008 @ 01:48 PM

    • State changed from “open” to “resolved”

    OK then.

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.

New-ticket Create new ticket

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!

People watching this ticket