Class: ActiveNode::Associations::CollectionAssociation
- Inherits:
-
Association
- Object
- Association
- ActiveNode::Associations::CollectionAssociation
- Defined in:
- lib/active_node/associations/collection_association.rb
Overview
Active Record Association Collection
CollectionAssociation is an abstract class that provides common stuff to ease the implementation of association proxies that represent collections. See the class hierarchy in AssociationProxy.
CollectionAssociation:
HasAndBelongsToManyAssociation => has_and_belongs_to_many
HasManyAssociation => has_many
HasManyThroughAssociation + ThroughAssociation => has_many :through
CollectionAssociation class provides common methods to the collections defined by has_and_belongs_to_many
, has_many
or has_many
with :through association option.
You need to be careful with assumptions regarding the target: The proxy does not fetch records from the database until it needs them, but new ones created with build
are added to the target. So, the target may be non-empty and still lack children waiting to be read from the database. If you look directly to the database you cannot assume that’s the entire collection because new records may have been added to the target, etc.
If you need to work on all current children, new and existing records, load_target
and the loaded
flag are your friends.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Association
#owner, #reflection, #rel_target, #target
Instance Method Summary collapse
-
#reset ⇒ Object
:nodoc:.
Methods inherited from Association
#ids_reader, #ids_writer, #initialize, #klass, #load_ids, #reader, #rel, #rels_loader, #rels_reader, #rels_writer, #save, #validate_type, #writer
Constructor Details
This class inherits a constructor from ActiveNode::Associations::Association
Instance Method Details
#reset ⇒ Object
:nodoc:
29 30 31 32 33 |
# File 'lib/active_node/associations/collection_association.rb', line 29 def reset super @target = owner.new_record? ? [] : nil @dirty = false end |