#40 ✓resolved
Georg Ledermann

Conflict with will_paginate

Reported by Georg Ledermann | December 18th, 2008 @ 09:25 AM

I stumpled upon a bug in conjunction with will_paginate.

This query works fine:

Contact.find :all, :conditions => { :addresses => { :zip_starts_with => '123' }}, :include => :addresses

It generates this query: SELECT contacts.id AS t0_r0, contacts.name AS t0_r1, addresses.id AS t1_r0, addresses.street AS t1_r1, addresses.po_box AS t1_r2, addresses.zip AS t1_r3 FROM contacts LEFT OUTER JOIN addresses ON addresses.contact_id = contacts.id WHERE (addresses.zip LIKE '123%')

But this (based on will_paginate) gets wrong:

Contact.paginate :all, :conditions => { :addresses => { :zip_starts_with => '123' }}, :include => :addresses, :page => 1

This is the error message, the addresses table is joined twice:

Mysql::Error: Not unique table/alias: 'addresses': 
SELECT DISTINCT contacts.id 
FROM contacts 
LEFT OUTER JOIN addresses ON addresses.contact_id = contacts.id 
LEFT OUTER JOIN addresses ON addresses.contact_id = contacts.id 
WHERE (addresses.zip LIKE '123%') LIMIT 0, 30

Using - Rails GEM 2.2.2 - will_paginate GEM 2.2.2 - Latest searchlogic plugin (12/15/08)

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson December 27th, 2008 @ 12:33 PM

    • State changed from “new” to “resolved”

    Can you try updating to the latest searchlogic and let me know if you still get this error? Thanks.

  • Ben Johnson

    Ben Johnson December 27th, 2008 @ 12:33 PM

    • State changed from “resolved” to “open”
  • Georg Ledermann

    Georg Ledermann December 27th, 2008 @ 01:00 PM

    Yes, this error still occurs with the latest commit of searchlogic... So far as I recall this works fine with some older version of searchlogic and/or Rails and/or will_paginate.

  • Ben Johnson

    Ben Johnson December 27th, 2008 @ 01:13 PM

    The problem is that your conditions are using searchlogic, which is fine, so searchlogic creates an autojoin for those conditions, then you are also including the same relationship. As a result :joins => :address and :include => :addresses are both passed to AR. AR does nothing to remove duplicates. So what I do with searchlogic is go to a lower level and remove duplicate joins. Right now I hook into the "construct_sql" methods to do this. It looks like will_paginate jumps all the way down to find_by_sql which skips that utility in searchlogic. I guess I need to go to a lower level. The reason I didn't want to do this is because that is not AR generated SQL, that is a level that hand written SQL could pass through. The problem with that is sub queries. If a person has sub queries that have a duplicate join that is perfectly fine, but searchlogic will remove it. I'm gonna see if I can filter out sub queries or something.

  • Ben Johnson

    Ben Johnson February 17th, 2009 @ 03:25 AM

    • State changed from “open” to “resolved”

    Let me know if this is still an issue. I believe I fixed this and forgot to update this ticket. Thanks!

  • Georg Ledermann

    Georg Ledermann February 18th, 2009 @ 03:39 AM

    The issue still exists in the current version of Searchlogic. Combining will_paginate with Searchlogic seems to be not a good idea...

  • frank butler

    frank butler July 18th, 2019 @ 03:48 AM

    Conflict with will_paginate is the site and below it there is some info related to it. You would like it if you try to visit this page for one reason or another. I didn’t know about coursework writing service uk before. It would also provide you sufficient info for the sake of understanding about the actual basics of the topic.

  • denis_richard

    denis_richard August 19th, 2019 @ 11:49 PM

    I am facing more errors in the conjunction during the run of the programs of my projects.so that way we can say that this is a very good post related to my problem. Now I am able to remove the errors of the in the project file schoollibrariesrock.org of my programs. We can also post the error here and get the right answer from the users of the site.

  • HoustonHacker

    HoustonHacker February 5th, 2020 @ 09:22 AM

    I’m stimulated when using the surpassing together with preachy showing that you choose to create in such bit of timing.
    best CBD oil for anxiety

  • jamelisa

    jamelisa February 5th, 2020 @ 09:33 AM

    Personally, I have found that to remain probably the most fascinating topics when it draws a parallel to. You may find two to three new levels inside L . a . Weight loss and any one someone is incredibly important. Initial stage may be real melting away rrn the body. lose weight Franklin County bail bonds

  • uzair awan

    uzair awan September 10th, 2020 @ 02:35 AM

    An easy way of understanding internet marketing is simply to look at it as getting exposure for the product or service you are offering on the internet. marketing 1on1 is an amazing agency

  • uzair awan

    uzair awan September 18th, 2020 @ 05:06 PM

    Thanks for providing recent updates regarding the concern, I look forward to read more. buy real facebook likes

  • nopsizerde

    nopsizerde October 4th, 2020 @ 04:25 PM

    Just admiring your work and wondering how you managed this blog so well. It’s so remarkable that I can't afford to not go through this valuable information whenever I surf the internet! zadiro

  • nopsizerde

    nopsizerde November 18th, 2020 @ 02:19 PM

    You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!. cpasbien

  • nopsizerde
  • nopsizerde

    nopsizerde November 28th, 2020 @ 02:08 PM

    i love reading this article so beautiful!!great job! voyance par telephone

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 ยป

Provides common named scopes and object based searching.

People watching this ticket