diff --git a/lib/counter_culture/counter.rb b/lib/counter_culture/counter.rb index 19b753d..ebb2fd5 100644 --- a/lib/counter_culture/counter.rb +++ b/lib/counter_culture/counter.rb @@ -165,15 +165,13 @@ def full_primary_key(klass) def foreign_key_value(obj, relation, was = false) original_relation = relation relation = relation.is_a?(Enumerable) ? relation.dup : [relation] - + if was first = relation.shift foreign_key_value = attribute_was(obj, relation_foreign_key(first)) klass = relation_klass(first, source: obj, was: was) if foreign_key_value - value = klass.where( - "#{klass.table_name}.#{relation_primary_key(first, source: obj, was: was)} = ?", - foreign_key_value).first + value = klass.where(relation_primary_key(first, source: obj, was: was) => foreign_key_value).first end else value = obj diff --git a/spec/counter_culture_spec.rb b/spec/counter_culture_spec.rb index c674278..d727801 100644 --- a/spec/counter_culture_spec.rb +++ b/spec/counter_culture_spec.rb @@ -165,7 +165,7 @@ def yaml_load(yaml) expect(user2.reload.review_approvals_count).to eq(69) end - it "works with multiple saves in one transcation" do + it "works with multiple saves in one transaction" do user = User.create product = Product.create