diff options
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 5c7770e739..6303ada87b 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -100,13 +100,25 @@ module ActiveRecord def interpolate_sql(sql, record = nil) @owner.send(:interpolate_sql, sql, record) end - + + def sanitize_sql(sql) + @association_class.send(:sanitize_sql, sql) + end + + def extract_options_from_args!(args) + @owner.send(:extract_options_from_args!, args) + end + private def load_collection - begin - @collection = find_all_records unless loaded? - rescue ActiveRecord::RecordNotFound - @collection = [] + if loaded? + @collection + else + begin + @collection = find_all_records + rescue ActiveRecord::RecordNotFound + @collection = [] + end end end @@ -114,25 +126,10 @@ module ActiveRecord raise ActiveRecord::AssociationTypeMismatch, "#{@association_class} expected, got #{record.class}" unless record.is_a?(@association_class) end - - def load_collection_to_array - return unless @collection_array.nil? - begin - @collection_array = find_all_records - rescue ActiveRecord::StatementInvalid, ActiveRecord::RecordNotFound - @collection_array = [] - end - end - - def duplicated_records_array(records) - records = [records] unless records.is_a?(Array) || records.is_a?(ActiveRecord::Associations::AssociationCollection) - records.dup - end - # Array#flatten has problems with rescursive arrays. Going one level deeper solves the majority of the problems. def flatten_deeper(array) array.collect { |element| element.respond_to?(:flatten) ? element.flatten : element }.flatten end end end -end
\ No newline at end of file +end |