Module: HasModerated::Associations::Collection::AssociationPatches
- Defined in:
- lib/has_moderated/associations/collection.rb
Instance Method Summary collapse
-
#add_to_target_with_moderation(record) ⇒ Object
moderate adding associations.
-
#delete_records_with_moderation(records, method) ⇒ Object
moderate removing associations.
Instance Method Details
#add_to_target_with_moderation(record) ⇒ Object
moderate adding associations
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/has_moderated/associations/collection.rb', line 6 def add_to_target_with_moderation record # If create is moderated, then add assoc. record normally, as create moderation # will prevent AR from creating the assoc. record in DB. # However, if create is not moderated, and owner is a new record, # then AR will create the assoc. record on # owner.save. In this case, add moderation as association now - see # create_moderation_with_hooks - the moderation will be saved when owner is saved, # so AR will properly set moderatable_id. create_moderated_and_new = owner.new_record? && owner.class.respond_to?(:moderated_create_options) if create_moderated_and_new || owner.moderation_disabled add_to_target_without_moderation record else owner.add_associations_moderated(self.reflection.name => [record]) record end end |
#delete_records_with_moderation(records, method) ⇒ Object
moderate removing associations
24 25 26 27 28 29 30 31 32 |
# File 'lib/has_moderated/associations/collection.rb', line 24 def delete_records_with_moderation(records, method) # method comes from :dependent => :destroy if owner.new_record? || owner.moderation_disabled delete_records_without_moderation(records, method) else # TODO only care for records which are already in database record_ids = records.map(&:id) owner.delete_associations_moderated(self.reflection.name => record_ids) end end |