diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-12-16 22:06:19 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-12-20 13:56:03 -0800 |
commit | 379c02267b3cbbf6d1ac48bc79ec6ea01af7b53a (patch) | |
tree | 0a5ef26fd1a39aeede161d966d20e3661c537945 /activerecord/lib/active_record/associations/association_collection.rb | |
parent | 880f8419c41db0aea4b7cf3abd74fe5d32fa04a7 (diff) | |
download | rails-379c02267b3cbbf6d1ac48bc79ec6ea01af7b53a.tar.gz rails-379c02267b3cbbf6d1ac48bc79ec6ea01af7b53a.tar.bz2 rails-379c02267b3cbbf6d1ac48bc79ec6ea01af7b53a.zip |
Specify insert_record with NotImplementedError in AssociationCollection, to indicate that subclasses should implement it. Also add save_record to reduce duplication.
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 11a7a725e5..51d8952eca 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -476,6 +476,17 @@ module ActiveRecord end private + # Do the relevant stuff to insert the given record into the association collection. The + # force param specifies whether or not an exception should be raised on failure. The + # validate param specifies whether validation should be performed (if force is false). + def insert_record(record, force = true, validate = true) + raise NotImplementedError + end + + def save_record(record, force, validate) + force ? record.save! : record.save(:validate => validate) + end + def create_record(attrs) attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash) ensure_owner_is_persisted! |