Class: Restforce::DB::Associations::Base
- Inherits:
-
Object
- Object
- Restforce::DB::Associations::Base
- Defined in:
- lib/restforce/db/associations/base.rb
Overview
Restforce::DB::Associations::Base defines an association between two mappings in the Registry.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#lookup ⇒ Object
readonly
Returns the value of attribute lookup.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#build(_database_record, _salesforce_record) ⇒ Object
Public: Build a record or series of records for the association defined by this class.
-
#fields ⇒ Object
Public: Get a list of fields which should be included in the Salesforce record’s lookups for any mapping including this association.
-
#initialize(name, through: nil) ⇒ Base
constructor
Public: Initialize a new Restforce::DB::Associations::Base.
-
#synced_for?(instance) ⇒ Boolean
Public: Has a record for this association already been synchronized for the supplied instance?.
Constructor Details
#initialize(name, through: nil) ⇒ Base
Public: Initialize a new Restforce::DB::Associations::Base.
name - The name of the ActiveRecord association to construct. through - The name of the lookup field on the Salesforce record.
17 18 19 20 |
# File 'lib/restforce/db/associations/base.rb', line 17 def initialize(name, through: nil) @name = name.to_sym @lookup = through.is_a?(Array) ? through.map(&:to_s) : through.to_s end |
Instance Attribute Details
#lookup ⇒ Object (readonly)
Returns the value of attribute lookup.
11 12 13 |
# File 'lib/restforce/db/associations/base.rb', line 11 def lookup @lookup end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/restforce/db/associations/base.rb', line 11 def name @name end |
Instance Method Details
#build(_database_record, _salesforce_record) ⇒ Object
Public: Build a record or series of records for the association defined by this class. Must be overridden in subclasses.
Raises a NotImplementedError.
26 27 28 |
# File 'lib/restforce/db/associations/base.rb', line 26 def build(_database_record, _salesforce_record) raise NotImplementedError end |
#fields ⇒ Object
Public: Get a list of fields which should be included in the Salesforce record’s lookups for any mapping including this association.
Returns a list of Salesforce fields this record should return.
35 36 37 |
# File 'lib/restforce/db/associations/base.rb', line 35 def fields [*lookup] end |
#synced_for?(instance) ⇒ Boolean
Public: Has a record for this association already been synchronized for the supplied instance?
instance - A Restforce::DB::Instances::Base.
Returns a Boolean.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/restforce/db/associations/base.rb', line 45 def synced_for?(instance) base_class = instance.mapping.database_model reflection = base_class.reflect_on_association(name) association_id = associated_salesforce_id(instance) return false unless association_id reflection.klass.exists?( mapping_for(reflection).lookup_column => association_id, ) end |