Permalink
Browse files

ActiveRecord 3.1 association compatibility

  • Loading branch information...
ianwhite committed Jan 10, 2012
1 parent 6b406c9 commit 2c7bd0623256fbdbef677e62b3b5fd9ef7c83dce
Showing with 14 additions and 2 deletions.
  1. +5 −0 History.txt
  2. +9 −2 lib/orm_adapter/adapters/active_record.rb
View
@@ -1,3 +1,8 @@
+== master
+
+ * ActiveRecord 3.1 association compatibility [Ian White]
+
+
== 0.0.5
* Adds Mongo Mapper adapter [Luke Cunningham]
@@ -69,8 +69,15 @@ def conditions_to_fields(conditions)
fields = {}
conditions.each do |key, value|
if value.is_a?(ActiveRecord::Base) && (assoc = klass.reflect_on_association(key.to_sym)) && assoc.belongs_to?
- fields[assoc.primary_key_name] = value.send(value.class.primary_key)
- fields[assoc.options[:foreign_type]] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
+
+ if ActiveRecord::VERSION::STRING < "3.1"
+ fields[assoc.primary_key_name] = value.send(value.class.primary_key)
+ fields[assoc.options[:foreign_type]] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
+ else # >= 3.1
+ fields[assoc.foreign_key] = value.send(value.class.primary_key)
+ fields[assoc.foreign_type] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
+ end
+
else
fields[key] = value
end

0 comments on commit 2c7bd06

Please sign in to comment.