Class: Restforce::DB::Associations::HasOne
- Inherits:
-
ForeignKey
- Object
- Base
- ForeignKey
- Restforce::DB::Associations::HasOne
- Defined in:
- lib/restforce/db/associations/has_one.rb
Overview
Restforce::DB::Associations::HasOne defines a relationship in which a Salesforce ID for this Mapping’s database record exists on the named database association’s Mapping.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#build(database_record, salesforce_record) ⇒ Object
Public: Construct a database record from a single Salesforce record associated with the supplied parent Salesforce record.
Methods inherited from ForeignKey
Methods inherited from Base
#fields, #initialize, #synced_for?
Constructor Details
This class inherits a constructor from Restforce::DB::Associations::Base
Instance Method Details
#build(database_record, salesforce_record) ⇒ Object
Public: Construct a database record from a single Salesforce record associated with the supplied parent Salesforce record.
database_record - An instance of an ActiveRecord::Base subclass. salesforce_record - A Hashie::Mash representing a Salesforce object.
Returns an Array of constructed association records.
19 20 21 22 23 24 25 |
# File 'lib/restforce/db/associations/has_one.rb', line 19 def build(database_record, salesforce_record) target = target_mapping(database_record) query = "#{lookup_field(target, database_record)} = '#{salesforce_record.Id}'" instance = target.salesforce_record_type.first(query) instance ? construct_for(database_record, instance) : [] end |