Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Problem with using complex joins

#149

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))

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

State: resolved
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Chris Wanstrath
    Chris Wanstrath
    • Assigned user changed from Chris Wanstrath to Mislav
    • State changed from new to open

    November 10th, 2007 @ 02:59 AM

  2. Mislav
    Mislav

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

    December 19th, 2007 @ 04:51 PM

  3. BrianTheCoder
    BrianTheCoder

    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.

    December 19th, 2007 @ 06:28 PM

  4. Mislav
    Mislav

    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.

    January 31st, 2008 @ 11:23 PM

  5. BrianTheCoder
    BrianTheCoder

    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.

    February 1st, 2008 @ 12:42 AM

  6. Mislav
    Mislav
    • State changed from open to resolved

    OK then.

    February 23rd, 2008 @ 01:48 PM

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.