Class: MassiveRecord::ORM::Relations::ProxyCollection
- Defined in:
- lib/massive_record/orm/relations/proxy_collection.rb
Overview
Proxy class for relations representing a collection
Direct Known Subclasses
MassiveRecord::ORM::Relations::Proxy::EmbedsMany, MassiveRecord::ORM::Relations::Proxy::ReferencesMany
Instance Attribute Summary
Attributes inherited from Proxy
#metadata, #proxy_owner, #proxy_target
Instance Method Summary collapse
-
#delete(*records) ⇒ Object
Deletes record(s) from the collection.
-
#delete_all ⇒ Object
Deletes all records from the relationship.
-
#destroy(*records) ⇒ Object
Destroy record(s) from the collection Each record will be asked to destroy itself as well.
-
#destroy_all ⇒ Object
Destroys all records.
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#load_proxy_target(options = {}) ⇒ Object
Loading proxy_targets will merge it with records found currently in proxy, to make sure we don’t remove any pushed proxy_targets only cause we load the proxy_targets.
- #replace(*records) ⇒ Object
- #reset(force = false) ⇒ Object
Methods inherited from Proxy
#blank?, #initialize, #inspect, #is_a?, #loaded!, #loaded?, #method_missing, #reload, #respond_to?, #to_param
Constructor Details
This class inherits a constructor from MassiveRecord::ORM::Relations::Proxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MassiveRecord::ORM::Relations::Proxy
Instance Method Details
#delete(*records) ⇒ Object
Deletes record(s) from the collection
57 58 59 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 57 def delete(*records) delete_or_destroy *records, :delete end |
#delete_all ⇒ Object
Deletes all records from the relationship. Does not destroy the records
75 76 77 78 79 80 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 75 def delete_all delete(load_proxy_target).tap do reset loaded! end end |
#destroy(*records) ⇒ Object
Destroy record(s) from the collection Each record will be asked to destroy itself as well
49 50 51 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 49 def destroy(*records) delete_or_destroy *records, :destroy end |
#destroy_all ⇒ Object
Destroys all records
64 65 66 67 68 69 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 64 def destroy_all destroy(load_proxy_target).tap do reset loaded! end end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 41 def empty? length == 0 end |
#first ⇒ Object
37 38 39 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 37 def first limit(1).first end |
#load_proxy_target(options = {}) ⇒ Object
Loading proxy_targets will merge it with records found currently in proxy, to make sure we don’t remove any pushed proxy_targets only cause we load the proxy_targets.
14 15 16 17 18 19 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 14 def load_proxy_target( = {}) proxy_target_before_load = proxy_target proxy_target_after_load = super self.proxy_target = (proxy_target_before_load + proxy_target_after_load).uniq end |
#replace(*records) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 26 def replace(*records) records.flatten! if records.length == 1 and records.first.nil? reset else delete_all concat(records) end end |
#reset(force = false) ⇒ Object
21 22 23 24 |
# File 'lib/massive_record/orm/relations/proxy_collection.rb', line 21 def reset(force = false) super @proxy_target = [] end |