Permalink
Browse files

ClassMethods.find() now respects includes()'d associations by merely …

…overwriting the original record's attributes instead of replacing the whole object.
  • Loading branch information...
DouweM committed Sep 4, 2011
1 parent 801b76e commit 9572c4da13ac57ddc1603d148b9fcb4ea780597f
Showing with 10 additions and 7 deletions.
  1. +4 −4 lib/citier/class_methods.rb
  2. +6 −3 lib/citier/instance_methods.rb
@@ -77,12 +77,12 @@ def self.find(*args) #overrides find to get all attributes
end
# Make a new array with the found records at the right places
- reloaded_tuples = []
- tuples.each do |tuple|
- reloaded_tuples << found_records.find { |found| found.id == tuple.id }
+ tuples.each do |tuple|
+ found_record = found_records.find { |found| found.id == tuple.id }
+ tuple.force_attributes(found_record.instance_variable_get(:@attributes), :merge => true, :clear_caches => false)
end
- return reloaded_tuples
+ return tuples
end
# In case of only one tuple, return it reloaded.
@@ -8,9 +8,12 @@ module ForcedWriters
def force_attributes(new_attributes, options = {})
new_attributes = @attributes.merge(new_attributes) if options[:merge]
@attributes = new_attributes
- @aggregation_cache = {}
- @association_cache = {}
- @attributes_cache = {}
+
+ if options[:clear_caches] != false
+ @aggregation_cache = {}
+ @association_cache = {}
+ @attributes_cache = {}
+ end
end
def force_changed_attributes(new_changed_attributes, options = {})

0 comments on commit 9572c4d

Please sign in to comment.