Skip to content

Commit

Permalink
Monkeypatch DataObjectsAdapter to not quote distance SQL queries. Fix f…
Browse files Browse the repository at this point in the history
  • Loading branch information
solon committed Mar 18, 2012
1 parent f798cce commit 1dd08c8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/dm-geokit/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ def has_geographic_location(name, options = {})
send :include, InstanceMethods
send :include, ::GeoKit::Mappable

# dm-geokit tries to push through some raw SQL to calculate the
# *_distance column. The dm-mysql-adapter and dm-postgres-adapter
# both quote and truncate what they believe to be a column name,
# meaning the query fails. This is a monkey patch to fix it:
if repository.adapter.is_a?(DataMapper::Adapters::DataObjectsAdapter)
repository.adapter.class.module_eval do
alias_method :orig_quote_name, :quote_name
def quote_name(name)
name.include?('(') ? name : orig_quote_name(name)
end
end
end

if defined?(DataMapper::Validations)
# since we return a custom object when this property is called, it breaks
# when dm-validations is included, so we set auto_validation to false if
Expand Down

0 comments on commit 1dd08c8

Please sign in to comment.