#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

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

Pages