restforce-db 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cf7836ccb586e04a24d23816d7c0ccea2c46ea9
4
- data.tar.gz: 089b7c3596be1f796de185ca25ded3a613f19848
3
+ metadata.gz: aa1372a2f8baf6d0af77a254f0360d6ad37aef11
4
+ data.tar.gz: 323beb3762fbf77ef7aa79f0465924260d22432d
5
5
  SHA512:
6
- metadata.gz: a4e81d52fc31bfdc3104b9720bceb1931410b7ad39d675a8bd9d172d1acedb3b99efe1f2c62937dca9d7b1c2fee57ad52161883988f0522df0876e41ed9552d4
7
- data.tar.gz: c0153e58647b5f60bbb610f9b8bb56c65bed0bc514f1d22f31567274bd56c368185f8798ca63359fb4635c51af0764abece5e947a717bb9d5c855dcd09371b51
6
+ metadata.gz: ad8b9ed0abf1e713b416a1e352f2c65de949dde70d7ee08db7c3fb40240995a90f7ac4b912b8e34cefa625db2630fd942b40d0a9b61f15661138a69548ed1706
7
+ data.tar.gz: 5d065ba0b3078f5b5f67c6f7cb8f1de520eb5049bde8cd31b2f73c5ef6cf029ff16ae9a7337e128dc1fae18828b2d54cbe028613b74511f33a62522376f772ce
data/README.md CHANGED
@@ -170,8 +170,7 @@ This _also_ defines an inverse relationship for a `belongs_to` relationship. The
170
170
 
171
171
  In the above example, `Dish__c` is a Salesforce object type which references the `Restaurant__c` object type through an aptly-named Lookup. There is no restriction on the number of `Dish__c` objects that may reference the same `Restaurant__c`, so we define this relationship as a `has_many` associaition in our `Restaurant` mapping.
172
172
 
173
- __NOTE__: Unlike `has_one` associations, `has_many` associations do not currently support multiple lookups from the same model. The Lookup is assumed
174
- to always refer to the `Id` of the parent object.
173
+ __NOTE__: If one side of an association has multiple possible lookup fields, the other side of the association is expected to declare a _single_ lookup field, which will be treated as the canonical lookup for that relationship. The Lookup is assumed to always refer to the `Id` of the object declaring the `has_many`/`has_one` side of the association.
175
174
 
176
175
  ### Seed your data
177
176
 
@@ -55,6 +55,25 @@ module Restforce
55
55
 
56
56
  private
57
57
 
58
+ # Internal: Get the appropriate Salesforce Lookup ID field for the
59
+ # passed mapping.
60
+ #
61
+ # mapping - A Restforce::DB::Mapping.
62
+ # database_record - An instance of an ActiveRecord::Base subclass.
63
+ #
64
+ # Returns a String or nil.
65
+ def lookup_field(mapping, database_record)
66
+ inverse = inverse_association_name(target_reflection(database_record))
67
+ association = mapping.associations.detect { |a| a.name == inverse }
68
+ return unless association
69
+
70
+ if lookup.is_a?(Array)
71
+ association.lookup
72
+ else
73
+ lookup
74
+ end
75
+ end
76
+
58
77
  # Internal: Get a list of all newly-constructed records based on this
59
78
  # association, for a set of lookups.
60
79
  #
@@ -76,21 +76,6 @@ module Restforce
76
76
  salesforce_instance.record[inverse_association.lookup] if salesforce_instance
77
77
  end
78
78
 
79
- # Internal: Get the appropriate Salesforce Lookup ID field for the
80
- # passed mapping.
81
- #
82
- # mapping - A Restforce::DB::Mapping.
83
- # database_record - An instance of an ActiveRecord::Base subclass.
84
- #
85
- # Returns a String or nil.
86
- def lookup_field(mapping, database_record)
87
- inverse = inverse_association_name(target_reflection(database_record))
88
- association = mapping.associations.detect { |a| a.name == inverse }
89
- return unless association
90
-
91
- association.lookup
92
- end
93
-
94
79
  end
95
80
 
96
81
  end
@@ -21,7 +21,7 @@ module Restforce
21
21
  @cache = cache
22
22
 
23
23
  target = target_mapping(database_record)
24
- lookup_id = "#{lookup} = '#{salesforce_record.Id}'"
24
+ lookup_id = "#{lookup_field(target, database_record)} = '#{salesforce_record.Id}'"
25
25
 
26
26
  records = []
27
27
  target.salesforce_record_type.each(conditions: lookup_id) do |instance|
@@ -21,7 +21,7 @@ module Restforce
21
21
  @cache = cache
22
22
 
23
23
  target = target_mapping(database_record)
24
- query = "#{lookup} = '#{salesforce_record.Id}'"
24
+ query = "#{lookup_field(target, database_record)} = '#{salesforce_record.Id}'"
25
25
 
26
26
  instance = target.salesforce_record_type.first(query)
27
27
  instance ? construct_for(database_record, instance) : []
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "1.2.8"
6
+ VERSION = "1.2.9"
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.8
4
+ version: 1.2.9
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-01 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord