will_paginate doesn't play nicely with Geokit
-
Chris Wanstrath
- 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
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
Hi Mislav,
Let me know if you need any more info from me. Thanks for looking into this!
-Vince
-
Chris Wanstrath
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
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
- State changed from open to hold
-
Vince Wadhwani
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')
-
Vince Wadhwani
Yeah! Thanks guys!!!
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.