restforce-db 1.2.11 → 1.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ef5b6219a597b42b72c8c636c9c82c84d4bfe8b
4
- data.tar.gz: 6e56a42dab74deb021bf98abc66f250a15d1d46d
3
+ metadata.gz: 54e87c10756c3eaa8d5a1307477ab6bcbe3743eb
4
+ data.tar.gz: 281164ea7eaaca49f8b2867b85232634fa63e326
5
5
  SHA512:
6
- metadata.gz: 3b3b4d3b7e38cd796708903f8eae824d84e3be02dced8c877e67fd8b24b8d387c0b5cb841618fb86f7269993331067c82837dcfebcec97a548c2884214718514
7
- data.tar.gz: 7bbeb680efe9b4b1839fb85825b3fa744c97e757442ed0da0814acfc94377ab8b6f3adf1397a356ea55adb104d66612ebac076c4edc127c7f446baf38b7cdcae
6
+ metadata.gz: 84649d0104478df05e9e1d4664781757a2a68f3e067861c25093f0a4df31c1587121648a57d4bcf8a992b1d8d7ad52702efbbc236fc87650ee7983f8ccf76c1d
7
+ data.tar.gz: 00509806871db7f6fb9046232882d7dd2564b72c6b541b1b73bd2f5f2af763ca47e2cc07001e51774fde2e50920a569fc1dbefa8d3d3ca6a4aed90c0cea266af
@@ -25,7 +25,7 @@ module Restforce
25
25
  instances = []
26
26
 
27
27
  for_mappings(database_record) do |mapping, lookup|
28
- lookup_id = salesforce_record[lookup]
28
+ lookup_id = deep_lookup(salesforce_record, lookup)
29
29
  lookups[mapping.lookup_column] = lookup_id
30
30
  instance = mapping.salesforce_record_type.find(lookup_id)
31
31
 
@@ -97,7 +97,29 @@ module Restforce
97
97
  inverse_association = association_for(reflection)
98
98
 
99
99
  salesforce_instance = instance.mapping.salesforce_record_type.find(instance.id)
100
- salesforce_instance.record[inverse_association.lookup] if salesforce_instance
100
+ deep_lookup(salesforce_instance.record, inverse_association.lookup) if salesforce_instance
101
+ end
102
+
103
+ # Internal: Get the value for a potentially nested lookup field.
104
+ #
105
+ # salesforce_record - A Hashie::Mash representing a Salesforce object.
106
+ # lookup - A String value lookup.
107
+ #
108
+ # Example:
109
+ #
110
+ # hash = { "Name" => "Chaplin", "Address_r" => { "City" => "Berlin" } }
111
+ #
112
+ # deep_lookup(hash, "Name")
113
+ # # => "Chaplin"
114
+ #
115
+ # deep_lookup(hash, "Address_r.City")
116
+ # # => "Berlin"
117
+ #
118
+ # Returns the value of the nested key.
119
+ def deep_lookup(salesforce_record, lookup)
120
+ lookup.split(".").inject(salesforce_record) do |hash, key|
121
+ hash[key]
122
+ end
101
123
  end
102
124
 
103
125
  end
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "1.2.11"
6
+ VERSION = "1.2.12"
7
7
 
8
8
  end
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.11
4
+ version: 1.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-06 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord