Class: CapsuleCRM::Associations::HasManyAssociation
- Inherits:
-
Object
- Object
- CapsuleCRM::Associations::HasManyAssociation
- Defined in:
- lib/capsule_crm/associations/has_many_association.rb
Instance Attribute Summary collapse
-
#association_name ⇒ Object
readonly
Returns the value of attribute association_name.
-
#defined_on ⇒ Object
readonly
Returns the value of attribute defined_on.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #embedded ⇒ Object
-
#initialize(association_name, defined_on, options) ⇒ HasManyAssociation
constructor
Public: Initialize a new CapsuleCRM::Associations::HasManyAssociation.
-
#macro ⇒ Object
Public: The type of association.
-
#proxy(parent, collection = nil) ⇒ Object
Public: Build the HasManyProxy object.
- #source ⇒ Object
- #target_klass ⇒ Object
Constructor Details
#initialize(association_name, defined_on, options) ⇒ HasManyAssociation
Public: Initialize a new CapsuleCRM::Associations::HasManyAssociation
association_name - The Symbox association name defined_on - The String name of the class that this association is defined on options - The Hash of association options
:class_name - The String name of the belongs to
class
:source - The Symbol name of the accessor method on
the belongs to class
Examples
CapsuleCRM::Associations::HasManyAssociation.new(
:opportunities, CapsuleCRM::Person, class_name:
'CapsuleCRM::Opportunity, source: :person
)
Returns a CapsuleCRM::Associations::HasManyAssociation
25 26 27 28 29 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 25 def initialize(association_name, defined_on, ) @association_name = association_name @options = @defined_on = defined_on end |
Instance Attribute Details
#association_name ⇒ Object (readonly)
Returns the value of attribute association_name.
4 5 6 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 4 def association_name @association_name end |
#defined_on ⇒ Object (readonly)
Returns the value of attribute defined_on.
4 5 6 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 4 def defined_on @defined_on end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 4 def @options end |
Instance Method Details
#embedded ⇒ Object
54 55 56 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 54 def @embedded ||= !![:embedded] end |
#macro ⇒ Object
Public: The type of association. Just a convenience method
Return a Symbol :has_many
50 51 52 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 50 def macro :has_many end |
#proxy(parent, collection = nil) ⇒ Object
Public: Build the HasManyProxy object
parent - The instance of the class that the has many assocation is defined on collection - An optional Array, Hash or Object to use as the target for the proxy. An Object will be coerced into an Array, a Hash will be turned in to an Object and then coerced into an Array.
Returns a CapsuleCRM::Associations::HasManyProxy
40 41 42 43 44 45 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 40 def proxy(parent, collection = nil) CapsuleCRM::Associations::HasManyProxy.new( parent, target_klass, build_target(parent, collection), source, ) end |
#source ⇒ Object
58 59 60 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 58 def source @source ||= [:source] || infer_source end |
#target_klass ⇒ Object
62 63 64 65 |
# File 'lib/capsule_crm/associations/has_many_association.rb', line 62 def target_klass @target_klass ||= ([:class_name] || infer_target_klass).constantize end |