geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

find method redefined #82

Open drobazko opened 9 years ago

drobazko commented 9 years ago

Hi, guys. Seems to be the issue.

Rails 4.1.12 ruby 2.1.0

restaurant.rb

class Restaurant < ActiveRecord::Base
...
acts_as_mappable :through => :address
...
end

So when I try rubyRestaurant.find(1) the exception raised.

2.1.0 :001 > Restaurant.find(1)
  Restaurant Load (12.4ms)  SELECT `restaurants`.* FROM `restaurants`  WHERE `restaurants`.`id` IN (1, '--- {}\n')
ActiveRecord::RecordNotFound: Couldn't find all Restaurants with 'id': (1, {}) (found 1 results, but was looking for 2)
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.12/lib/active_record/relation/finder_methods.rb:320:in `raise_record_not_found_exception!'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.12/lib/active_record/relation/finder_methods.rb:452:in `find_some'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.12/lib/active_record/relation/finder_methods.rb:416:in `find_with_ids'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.12/lib/active_record/relation/finder_methods.rb:68:in `find'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/activerecord-4.1.12/lib/active_record/querying.rb:3:in `find'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/geokit-rails-1.1.4/lib/geokit-rails/acts_as_mappable.rb:153:in `find'
    from (irb):1
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/railties-4.1.12/lib/rails/commands/console.rb:90:in `start'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/railties-4.1.12/lib/rails/commands/console.rb:9:in `start'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/railties-4.1.12/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/railties-4.1.12/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/drobazko/.rvm/gems/ruby-2.1.0/gems/railties-4.1.12/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:10:in `require'
    from bin/rails:10:in `<main>'
JPMallow commented 8 years ago

Any update on this issue?

drobazko commented 8 years ago

@JPMallow, I have monkey patched it.

config/initializers/geo_patch.rb

module Geokit
  module ActsAsMappable
    module SingletonMethods
      def find(*args)
        prepare_for_find_or_count(:find, args)
        args.last.is_a?(Hash) && args.last.empty? ? super(*args[0..-2]) : super(*args)
      end
    end
  end
end
JPMallow commented 8 years ago

Thanks @drobazko But, I have moved to geocoder gem as it does my work as charm.