diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-01 19:50:23 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-01 19:50:23 +0000 |
commit | 6bd672eb0d50fcf3437d7fa244245397747bf7a7 (patch) | |
tree | 77a139b962f3b9d0acd838c4cbee554944ebf9a5 /activerecord/lib/active_record/associations/association_collection.rb | |
parent | 86df396491bb4769884e3fc8b2d214bed04b8134 (diff) | |
download | rails-6bd672eb0d50fcf3437d7fa244245397747bf7a7.tar.gz rails-6bd672eb0d50fcf3437d7fa244245397747bf7a7.tar.bz2 rails-6bd672eb0d50fcf3437d7fa244245397747bf7a7.zip |
Added that Base#find takes an optional options hash, including :conditions. Base#find_on_conditions deprecated in favor of #find with :conditions #407 [bitsweat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@305 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
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 |