#59 ✓resolved
Vince Wadhwani

will_paginate doesn't play nicely with Geokit

Reported by Vince Wadhwani | July 15th, 2007 @ 10:34 PM

There's another plugin called geokit which extends Activerecord so you can do a find based on a point of origin and a distance around that origin. e.g. a Find can be created like this:

@results = Address.find(:all, :include => [:place], :origin => @location, :conditions =>['distance < ? AND category_id = ?', @location.distance, @category])

However, will_paginate will not recognize that.. it throws an invalid key error for :origin

More details in this thread on railsforum:

http://railsforum.com/viewtopic....

Comments and changes to this ticket

  • Chris Wanstrath

    Chris Wanstrath July 15th, 2007 @ 10:34 PM

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

    For the record, I think overriding #find is always a bad idea. I'll let Mislav make a decision on this, though.

  • Mislav

    Mislav July 15th, 2007 @ 10:34 PM

    Will Paginate should work even when the find method is messed with. I even have unit tests for this! I'll probably investigate using ruby-debug and test/console :)

  • Vince Wadhwani

    Vince Wadhwani July 15th, 2007 @ 10:34 PM

    Hi Mislav,

    Let me know if you need any more info from me. Thanks for looking into this!

    -Vince

  • Chris Wanstrath

    Chris Wanstrath July 15th, 2007 @ 10:34 PM

    Okay, what's weird is the stack trace in http://railsforum.com/viewtopic.... doesn't touch acts_as_mappable. You can see method_missing line #105 calls count in calculations.rb -- it should, I think, be calling count in acts_as_mappable. This may be part of the issue.

  • Chris Wanstrath

    Chris Wanstrath July 15th, 2007 @ 10:34 PM

    Did some hacking with Andre (of Geokit fame) tonight. Made commit [290] which may or may not fix your problem. I couldn't really reproduce it, but I was getting a similar error in the same place which is now fixed.

    Make sure you have the newest version of Geokit, newest will_paginate, and that you are doing acts_as_mappable on your class.

  • Chris Wanstrath

    Chris Wanstrath July 15th, 2007 @ 10:34 PM

    • State changed from “open” to “hold”
  • Vince Wadhwani

    Vince Wadhwani July 15th, 2007 @ 10:34 PM

    Ok, I'm using v296 of will_paginate and v37 of geokit. This is the call in my show controller:

    @places = Address.paginate :per_page => 10, :page => params[:page],

    :include => [:place], :origin => @location,

    :conditions =>['distance < ? AND category_id = ?', @location.distance, @category],

    :order => 'name asc'

    Whereas previously I got an error saying Unknown Key, this time I get a straight mysql error saying:

    Mysql::Error: #42S22Unknown column 'category_id' in 'where clause': SELECT count(*) AS count_all FROM addresses WHERE ( (ACOS(COS(0.679100630633986)*COS(-1.34459484895235)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+

    COS(0.679100630633986)*SIN(-1.34459484895235)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+

    SIN(0.679100630633986)*SIN(RADIANS(addresses.lat)))*3963)

    < 10.0 AND store_category_id = 1)

    Interestingly, if I take out the category_id as a requirement in the conditions, it does work. Since category_id is not part of the address model (it's part of the place model) I suspect that the [:include => place] isn't being followed.

    Address:

    def self.up

    create_table :addresses do |t|

    t.column :place_id, :integer

    t.column :address, :string

    t.column :lat, :float

    t.column :lng, :float

    t.column :created_at, :datetime

    t.column :updated_at, :datetime

    end

    Place:

    def self.up

    create_table :places do |t|

    t.column :name, :string

    t.column :description, :string, :limit => 1000

    t.column :link, :string, :limit => 120

    t.column :user_id, :integer

    t.column :category_id, :integer, :limit => 3

    t.column :created_at, :datetime

    end

    Category

    def self.up

    create_table :categories do |t|

    t.column :name, :string

    end

    The original find still works:

    @places = Address.find(:all, :include => [:place], :origin => @location, :conditions =>['distance < ? AND category_id = ?', @location.distance, @category], :order => 'name asc')

  • Mislav

    Mislav July 15th, 2007 @ 10:34 PM

    • State changed from “hold” to “resolved”
  • Vince Wadhwani

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

Pages