global-registry-bindings 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +248 -57
- data/lib/global_registry_bindings/entity/entity_type_methods.rb +1 -1
- data/lib/global_registry_bindings/entity/push_relationship_methods.rb +4 -4
- data/lib/global_registry_bindings/entity/relationship_type_methods.rb +5 -5
- data/lib/global_registry_bindings/global_registry_bindings.rb +0 -97
- data/lib/global_registry_bindings/model/push_relationship.rb +2 -2
- data/lib/global_registry_bindings/options/entity_class_options.rb +4 -4
- data/lib/global_registry_bindings/options/entity_instance_options.rb +6 -8
- data/lib/global_registry_bindings/options/entity_options_parser.rb +13 -7
- data/lib/global_registry_bindings/options/relationship_class_options.rb +11 -11
- data/lib/global_registry_bindings/options/relationship_instance_options.rb +11 -15
- data/lib/global_registry_bindings/options/relationship_options_parser.rb +27 -25
- data/lib/global_registry_bindings/version.rb +1 -1
- data/spec/acceptance/global_registry_bindings_spec.rb +7 -7
- data/spec/internal/app/models/address.rb +1 -1
- data/spec/internal/app/models/assignment.rb +4 -4
- data/spec/internal/app/models/community.rb +4 -4
- data/spec/internal/app/models/country.rb +1 -1
- data/spec/internal/app/models/namespaced/person.rb +4 -4
- data/spec/internal/app/models/organization.rb +2 -2
- data/spec/internal/log/test.log +6363 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 746c1c5f80dc01e231c4da4f98293da950e4dc00
|
4
|
+
data.tar.gz: 0bd3877aebe765e52b9674f05788eddf409f3e1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6033a8a498c1547f60aeaeb1a78a8305742d12907d6917de62a4fd148f235e39f0a045d9010e38bd73ae5b75b0a8fd1d2a1ff6838a86efaab15ec65d687e2d6
|
7
|
+
data.tar.gz: 256bd53774e56971f3cf5f4291edc0a128ebd77f2ae16f9658970d1612ffef35e662d7efe807d4f23903259e0b1e13c1436665dcb46979d3bee2282f9e8a01bb
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
Global Registry Bindings are a set of bindings to push ActiveRecord models to the Global Registry.
|
4
4
|
|
5
|
-
|
6
5
|
## Installation
|
7
6
|
|
8
7
|
Add to your Gemfile:
|
@@ -27,7 +26,8 @@ Make sure sidekiq is configured. See [Using Redis](https://github.com/mperham/si
|
|
27
26
|
|
28
27
|
To make use of `global-registry-bindings` your model will need a few additional columns.
|
29
28
|
To push models to Global Registry, you will need a `global_registry_id` column. You additionally need a
|
30
|
-
`global_registry_mdm_id` to pull a Global Registry MDM (master data model) id.
|
29
|
+
`global_registry_mdm_id` to pull a Global Registry MDM (master data model) id. Additionally, relationships will also
|
30
|
+
require columns to track relationship ids. These columns should be of type
|
31
31
|
`:string` or `:uuid` and allow null values. Column names are customizable through options.
|
32
32
|
```ruby
|
33
33
|
class CreatePeople < ActiveRecord::Migration
|
@@ -47,81 +47,77 @@ end
|
|
47
47
|
|
48
48
|
## Options
|
49
49
|
|
50
|
-
You can pass various options to the `global_registry_bindings` method.
|
50
|
+
You can pass various options to the `global_registry_bindings` method. Options will list whether they are valid for
|
51
|
+
`:entity`, `:relationship` or both bindings.
|
51
52
|
|
52
53
|
* `:binding`: Type of Global Registry binding. Either `:entity` or `:relationship`.
|
53
54
|
(default: `:entity`)
|
54
|
-
|
55
|
-
* `:id_column`: Column used to track the Global Registry ID for the model instance or relationship entity.
|
56
|
-
Can be a :string or :uuid column. (default: `:global_registry_id`) **[`:entity`, `:relationship`]**
|
57
55
|
|
58
|
-
* `:
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
* `:id_column`: Column used to track the Global Registry ID for the entity or relationship entity.
|
57
|
+
Can be a `:string` or `:uuid` column. (default: `:global_registry_id`) **[`:entity`, `:relationship`]**
|
58
|
+
|
59
|
+
* `:type`: Global Registry Entity Type name. This name should be unique in Global Registry or point to an existing
|
60
|
+
Entity Type. When used in a `:relationship` binding, it is required to be unique across all relationships on this
|
61
|
+
ActiveRecord class. Accepts a Symbol or a Proc. Symbol is the name of the Entity Type, Proc
|
62
|
+
is passed the model instance and must return a symbol which is the Entity Type. Defaults to the underscored
|
63
|
+
name of the class. Ex: ```type: proc { |model| model.name.to_sym }```. **[`:entity`, `:relationship`]**
|
62
64
|
|
63
65
|
* `:push_on`: Array of Active Record lifecycle events used to push changes to Global Registry.
|
64
66
|
(default: `[:create, :update, :destroy]`) **[`:entity`]**
|
65
67
|
|
66
|
-
* `:
|
67
|
-
global_registry_bindings in order to determine foreign_key for use in exclude. Used to create a
|
68
|
+
* `:parent`: Name of the Active Record parent association (`:belongs_to`, `:has_one` ...). Must be defined
|
69
|
+
before calling `global_registry_bindings` in order to determine foreign_key for use in exclude. Used to create a
|
68
70
|
hierarchy or to push child entity types. (Ex: person -> address) (default: `nil`) **[`:entity`]**
|
69
71
|
|
70
|
-
* `:
|
72
|
+
* `:parent_class`: Active Record Class name of the parent. Required if `:parent` can not be used
|
71
73
|
to determine the parent class. This can happen if parent is defined by another gem, like `ancestry`.
|
72
74
|
(default: `nil`) **[`:entity`]**
|
73
75
|
|
74
76
|
* `:primary_binding`: Determines what type of global-registry-binding the primary association points to. Defaults
|
75
|
-
to `:entity`, but can be set to a `:relationship` type
|
77
|
+
to `:entity`, but can be set to a `:relationship` type (ex: `:assignment`) to create a relationship_type
|
76
78
|
between a relationship and an entity. (default: `:entity`) **[`:relationship`]**
|
77
79
|
|
78
|
-
* `:
|
79
|
-
global_registry_bindings in order to determine foreign_key for use in exclude.
|
80
|
-
**[`:relationship`]**
|
80
|
+
* `:primary`: Name of the Active Record primary association. Must be defined before calling
|
81
|
+
global_registry_bindings in order to determine foreign_key for use in exclude. If missing, `:primary` is assumed to be
|
82
|
+
the current Active Record model. (default: `nil`) **[`:relationship`]**
|
81
83
|
|
82
|
-
* `:
|
83
|
-
used to determine the
|
84
|
+
* `:primary_class`: Class name of the primary model. Required if `:primary` can not be
|
85
|
+
used to determine the primary class. This can happen if parent is defined by another gem, like `ancestry`.
|
84
86
|
(default: `self.class`) **[`:relationship`]**
|
85
87
|
|
86
|
-
* `:
|
87
|
-
not be determined from `:
|
88
|
-
**[`:relationship`]**
|
88
|
+
* `:primary_foreign_key`: Foreign Key column for the primary association. Used if foreign_key can
|
89
|
+
not be determined from `:primary`. (default: `:primary.foreign_key`) **[`:relationship`]**
|
89
90
|
|
90
|
-
* `:
|
91
|
+
* `:primary_name`: **Required** Name of primary relationship (Global Registry relationship1). Should be unique
|
92
|
+
to prevent ambiguous relationship names. (default: `nil`) **[`:relationship`]**
|
93
|
+
|
94
|
+
* `:related`: Name of the Active Record related association. Active Record association must be
|
91
95
|
defined before calling global_registry_bindings in order to determine the foreign key.
|
92
96
|
(default: `nil`) **[`:relationship`]**
|
93
97
|
|
94
|
-
* `:
|
98
|
+
* `:related_class`: Class name of the related model. Required if `:related_association` can not be
|
95
99
|
used to determine the related class. (default: `nil`) **[`:relationship`]**
|
96
100
|
|
97
|
-
* `:
|
98
|
-
not be determined from `:
|
99
|
-
**[`:relationship`]**
|
100
|
-
|
101
|
-
* `:primary_relationship_name`: **Required** Name of primary relationship. Should be unique to prevent
|
102
|
-
ambiguous relationship names. (default: `nil`) **[`:relationship`]**
|
101
|
+
* `:related_foreign_key`: Foreign Key column for the related association. Used if foreign_key can
|
102
|
+
not be determined from `:related`. (default: `:related.foreign_key`) **[`:relationship`]**
|
103
103
|
|
104
|
-
* `:
|
105
|
-
ambiguous relationship names (default: `nil`) **[`:relationship`]**
|
104
|
+
* `:related_name`: **Required** Name of the related relationship (Global Registry relationship2). Should be
|
105
|
+
unique to prevent ambiguous relationship names (default: `nil`) **[`:relationship`]**
|
106
106
|
|
107
|
-
* `:
|
107
|
+
* `:related_type`: Name of the related association Entity Type. Required if unable to determined
|
108
108
|
`:type` from related. (default: `nil`) **[`:relationship`]**
|
109
109
|
|
110
110
|
* `:related_global_registry_id`: Global Registry ID of a remote related entity. Proc or Symbol. Implementation
|
111
111
|
should cache this as it may be requested multiple times. (default: `nil`) **[`:relationship`]**
|
112
112
|
|
113
|
-
* `:
|
114
|
-
(default: `true`) **[`:relationship`]**
|
115
|
-
|
116
|
-
* `:ensure_entity_type`: Ensure Global Registry Entity Type exists and is up to date.
|
117
|
-
(default: `true`) **[`:entity`]**
|
113
|
+
* `:ensure_type`: Ensure Global Registry Entity Type or Relationship Entity Type exists and is up to date.
|
114
|
+
(default: `true`) **[`:entity`, `:relationship`]**
|
118
115
|
|
119
116
|
* `:client_integration_id`: Client Integration ID for relationship. Proc or Symbol.
|
120
|
-
(default: `:
|
117
|
+
(default: `:primary.id`) **[`:relationship`]**
|
121
118
|
|
122
119
|
* `:include_all_columns`: Include all model columns in the fields to push to Global Registry. If `false`, fields must
|
123
|
-
be defined in the `:fields` option. (default: `false`)
|
124
|
-
**[`:entity`, `:relationship`]**
|
120
|
+
be defined in the `:fields` option. (default: `false`) **[`:entity`, `:relationship`]**
|
125
121
|
|
126
122
|
* `:exclude`: Array, Proc or Symbol. Array of Model fields (as symbols) to exclude when pushing to Global
|
127
123
|
Registry. Array Will additionally include `:mdm_id_column` and `:parent_association` foreign key when defined.
|
@@ -142,35 +138,230 @@ option is nil or empty. (default: `nil`) **[`:entity`]**
|
|
142
138
|
* `:mdm_timeout`: Only pull mdm information at most once every `:mdm_timeout`. (default: `1.minute`)
|
143
139
|
**[`:entity`]**
|
144
140
|
|
145
|
-
##
|
141
|
+
## Entities
|
142
|
+
|
143
|
+
`global-registry-bindings` default bindings is to push an Active Record class as an Entity to Global Registry.
|
144
|
+
This can be used to push root level entities, entities with a parent and entities with a hierarchy. You can also
|
145
|
+
enable fetching of a Master Data Model from Global Registry.
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
|
147
|
+
See [About Entities](https://github.com/CruGlobal/global_registry_docs/wiki/About-Entities) for more
|
148
|
+
information on Global Registry Entities.
|
149
|
+
|
150
|
+
### Root Entity
|
151
|
+
```ruby
|
152
|
+
class Person < ActiveRecord::Base
|
153
|
+
global_registry_bindings mdm_id_column: :global_registry_mdm_id
|
154
|
+
end
|
155
|
+
```
|
156
|
+
This will push the Person Active Record model to Global Registry as a `person` Entity Type, storing the resulting id
|
157
|
+
value in the `global_registry_id` column, as well as fetching a `master_person` Entity and storing it in the
|
158
|
+
`global_registry_mdm_id` column.
|
150
159
|
|
160
|
+
### Parent/Child Entity
|
151
161
|
```ruby
|
152
162
|
class Person < ActiveRecord::Base
|
153
|
-
|
154
|
-
global_registry_bindings
|
155
|
-
|
163
|
+
has_many :addresses, inverse_of: :person
|
164
|
+
global_registry_bindings
|
165
|
+
end
|
166
|
+
|
167
|
+
class Address < ActiveRecord::Base
|
168
|
+
belongs_to :person
|
169
|
+
global_registry_bindings
|
170
|
+
end
|
171
|
+
```
|
172
|
+
This will push the Person model to Global Registry as a `person` Entity Type, and the Address model as an `address`
|
173
|
+
Entity Type that has a parent of `person`.
|
174
|
+
|
175
|
+
### Entity Hierarchy
|
176
|
+
```ruby
|
177
|
+
class Ministry < ActiveRecord::Base
|
178
|
+
has_many :children, class_name: 'Ministry', foreign_key: :parent_id
|
179
|
+
belongs_to :parent, class_name: 'Ministry'
|
156
180
|
|
157
|
-
|
181
|
+
global_registry_bindings parent: :parent
|
182
|
+
end
|
183
|
+
```
|
184
|
+
This will push the Ministry model to Global Registry as well as the parent/child hierarchy. Global Registry only allows
|
185
|
+
a single parent, and does not allow circular references. Hierarchy is also EntityType specific, and not saved per
|
186
|
+
system in Global Registry, meaning, the last system to push a parent wins (You can accidently override another systems
|
187
|
+
hierarchy. This should be avoided and instead pushed as a relationship if needed).
|
188
|
+
|
189
|
+
## Relationships
|
190
|
+
|
191
|
+
`global-registry-bindings` can also be configured to push relationships between models to Global Registry. All
|
192
|
+
relationships in Global Registry are many to many, but by using Active Record associations, we can simulate one to many
|
193
|
+
and one to one.
|
194
|
+
|
195
|
+
See [About Relationships](https://github.com/CruGlobal/global_registry_docs/wiki/About-Relationships) for more
|
196
|
+
information on Global Registry relationships.
|
197
|
+
|
198
|
+
### Many-to-Many with join model
|
199
|
+
```ruby
|
200
|
+
class Ministry < ActiveRecord::Base
|
201
|
+
has_many :assignments
|
202
|
+
has_many :people, through: :assignments
|
203
|
+
global_registry_bindings
|
204
|
+
end
|
158
205
|
|
159
|
-
|
206
|
+
class Person < ActiveRecord::Base
|
207
|
+
has_many :assignments
|
208
|
+
has_many :ministries, through: :assignments
|
209
|
+
global_registry_bindings
|
210
|
+
end
|
211
|
+
|
212
|
+
class Assignment < ActiveRecord::Base
|
213
|
+
belongs_to :person
|
214
|
+
belongs_to :ministry
|
215
|
+
global_registry_bindings binding: :relationship,
|
216
|
+
primary: :person,
|
217
|
+
primary_name: :people,
|
218
|
+
related: :ministry,
|
219
|
+
related_name: :ministries
|
220
|
+
end
|
221
|
+
```
|
222
|
+
This will push Ministry and Person to Global Registry as Entities, and Assignment join model as a relationship between
|
223
|
+
them, storing the relationship id in the Assignment `global_registry_id` column.
|
224
|
+
|
225
|
+
### One-to-Many
|
226
|
+
```ruby
|
227
|
+
class Person < ActiveRecord::Base
|
228
|
+
has_many :pets
|
229
|
+
global_registry_bindings
|
230
|
+
end
|
231
|
+
|
232
|
+
class Pet < ActiveRecord::Base
|
233
|
+
belongs_to :person
|
234
|
+
global_registry_bindings binding: :relationship,
|
235
|
+
type: :owner,
|
236
|
+
related: :person
|
237
|
+
end
|
238
|
+
```
|
239
|
+
|
240
|
+
## Fields and Values
|
241
|
+
|
242
|
+
Both Entities and Relationships include fields that will be pushed to Global Registry.
|
243
|
+
|
244
|
+
### Fields
|
245
|
+
|
246
|
+
The fields that are pushed to Global Registry are defined with a combination of the `:fields`, `:exclude` and
|
247
|
+
`:include_all_columns` options. The `:fields` option defines the fields and field types to be pushed. If
|
248
|
+
`:include_all_columns` is set to `true`,`:fields` are appended to the list of all model columns. `:exclude` option is
|
249
|
+
then used to remove fields from the list. If `:ensure_type` is `true`, the Global Registry EntityType or
|
250
|
+
RelationshipType will be updated when new fields are defined. If `:ensure_type` is false, and fields are missing
|
251
|
+
from the EntityType or RelationshipType, Global Registry will throw an error. It is the developers job to ensure Global
|
252
|
+
Registry Entity and Relationship Types are accurate when `:ensure_type` is disabled.
|
253
|
+
|
254
|
+
Given an Active Record model:
|
255
|
+
```ruby
|
256
|
+
create_table :products do |t|
|
257
|
+
t.string :name
|
258
|
+
t.text :description
|
259
|
+
t.string :global_registry_id
|
260
|
+
t.references :supplier, index: true, foreign_key: true
|
261
|
+
t.string :supplier_gr_rel_id, null: true, default: nil
|
262
|
+
t.timestamps null: false
|
263
|
+
end
|
264
|
+
```
|
265
|
+
And the following `global_registry_bindings`:
|
266
|
+
```ruby
|
267
|
+
class Product < ActiveRecord::Base
|
268
|
+
belongs_to :supplier
|
269
|
+
global_registry_bindings fields: { name: string, description: :text }
|
270
|
+
end
|
271
|
+
```
|
272
|
+
Will result in the following fields `{:name=>:string, :description=>:text}`
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
class Product < ActiveRecord::Base
|
276
|
+
belongs_to :supplier
|
277
|
+
global_registry_bindings include_all_columns: true,
|
278
|
+
exclude: %i[supplier_id]
|
279
|
+
end
|
280
|
+
```
|
281
|
+
Will result in the following fields `{:name=>:string, :description=>:text}`, `:id`, `:global_registry_id` and timestamp
|
282
|
+
fields are excluded by default when `:include_all_columns` is `true`.
|
283
|
+
|
284
|
+
You can add additional fields by specifying them in the `:fields` option.
|
285
|
+
```ruby
|
286
|
+
class Product < ActiveRecord::Base
|
287
|
+
belongs_to :supplier
|
288
|
+
global_registry_bindings include_all_columns: true,
|
289
|
+
exclude: %i[supplier_id],
|
290
|
+
fields: {color: :string}
|
291
|
+
end
|
292
|
+
```
|
293
|
+
Will result in the following fields `{:name=>:string, :description=>:text, :color=>:string}`
|
294
|
+
|
295
|
+
Relationships can also include fields:
|
296
|
+
```ruby
|
297
|
+
class Product < ActiveRecord::Base
|
298
|
+
belongs_to :supplier
|
299
|
+
global_registry_bindings fields: { name: string, description: :text }
|
300
|
+
global_registry_bindings binding: :relationship,
|
301
|
+
type: :supplier,
|
302
|
+
related: :supplier,
|
303
|
+
id_column: :supplier_gr_rel_id,
|
304
|
+
extra: {quantity: :integer}
|
305
|
+
end
|
306
|
+
```
|
307
|
+
Will result in the following fields `{:quantity=>:integer}`
|
308
|
+
|
309
|
+
`:fields` and `:exclude` can also be defined as a proc, labmda or symbol. Symbol must point to a method that will
|
310
|
+
return either the extra or excluded fields.
|
311
|
+
```ruby
|
312
|
+
class Product < ActiveRecord::Base
|
313
|
+
belongs_to :supplier
|
314
|
+
global_registry_bindings include_all_columns: true,
|
315
|
+
exclude: ->(type, model) { model.name == 'Sprocket' ? [] : %i[:field1] },
|
316
|
+
fields: :extra_fields
|
317
|
+
def extra_fields(type)
|
318
|
+
# type === :product
|
319
|
+
{field1: :string, field2: :boolean}
|
320
|
+
end
|
321
|
+
end
|
322
|
+
```
|
323
|
+
|
324
|
+
You can debug the current fields that will be pushed using the rails console:
|
325
|
+
```ruby
|
326
|
+
irb> Product.first.entity_columns_to_push
|
327
|
+
=> {:name=>:string, :description=>:text}
|
328
|
+
irb> Product.first.relationship_entity_columns(:supplier)
|
329
|
+
=> {}
|
330
|
+
```
|
331
|
+
|
332
|
+
### Values
|
333
|
+
|
334
|
+
When a model is pushed to global registry, `global-registry-bindings` will attempt to determined the values for
|
335
|
+
each of the fields. This is done by calling the field name on the model. If the model responds, the value will be sent
|
336
|
+
with the entity. Model and implement or override values with a few different options. They can use
|
337
|
+
`alias_attribute :new_name, :old_name`, define a method `def field_name; "value"; end` or override
|
338
|
+
`entity_attributes_to_push` or `relationship_attributes_to_push` respectively. When the `*_attributes_to_push` methods
|
339
|
+
are used, you can modify values for other attributes as well as add additional fields and values. This is helpful
|
340
|
+
when adding fields and values which may not be tracked directly on this model. An instance of this is adding an
|
341
|
+
`authentication: { guid: 'UUID' }` field to a `person` entity_type to utilize Global Registry linked_identities.
|
342
|
+
See [Entity Matching](https://github.com/CruGlobal/global_registry_docs/wiki/Entity-Matching).
|
343
|
+
|
344
|
+
```ruby
|
345
|
+
class Person < ActiveRecord::Base
|
346
|
+
alias_attribute :field1, :name
|
347
|
+
|
348
|
+
global_registry_bindings fields: { name: string, description: :text, field1: :boolean, field2: :integer }
|
160
349
|
|
161
|
-
|
162
|
-
|
163
|
-
"#{first_name} #{last_name}"
|
350
|
+
def field2
|
351
|
+
"#{name}:2"
|
164
352
|
end
|
165
353
|
|
166
|
-
# Override entity_attributes_to_push to add or modify fields and values
|
167
354
|
def entity_attributes_to_push
|
168
|
-
|
169
|
-
|
170
|
-
|
355
|
+
attrs = super # Calls super to get field values, then modify them.
|
356
|
+
attrs[:description] = "Huge: #{attrs[:description]}"
|
357
|
+
attrs[:authentication] = { guid: 'UUID' }
|
358
|
+
attrs
|
171
359
|
end
|
172
360
|
end
|
173
361
|
```
|
362
|
+
As an example, this would alias `field1` to `name` and use the method `field2` to determine the value for `field2`. It
|
363
|
+
subsequently changes the value of `:description` and adds an `:authentication` field using the
|
364
|
+
`entity_attributes_to_push` override.
|
174
365
|
|
175
366
|
## Example Models
|
176
367
|
|
@@ -9,7 +9,7 @@ module GlobalRegistry #:nodoc:
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
def push_entity_type_to_global_registry
|
12
|
-
return unless global_registry_entity.
|
12
|
+
return unless global_registry_entity.ensure_type?
|
13
13
|
parent_entity_id = parent_entity_type_id
|
14
14
|
entity_type = Rails.cache.fetch(entity_type_cache_key, expires_in: 1.hour) do
|
15
15
|
GlobalRegistry::EntityType.get('filters[name]' => global_registry_entity.type,
|
@@ -37,7 +37,7 @@ module GlobalRegistry #:nodoc:
|
|
37
37
|
relationships = Array.wrap entity.dig(
|
38
38
|
'entity',
|
39
39
|
relationship.primary_type.to_s,
|
40
|
-
"#{relationship.
|
40
|
+
"#{relationship.related_name}:relationship"
|
41
41
|
)
|
42
42
|
relationships.detect do |rel|
|
43
43
|
cid = rel['client_integration_id']
|
@@ -79,7 +79,7 @@ module GlobalRegistry #:nodoc:
|
|
79
79
|
|
80
80
|
def relationship_entity
|
81
81
|
{ entity: { relationship.primary_type => {
|
82
|
-
"#{relationship.
|
82
|
+
"#{relationship.related_name}:relationship" =>
|
83
83
|
model.relationship_attributes_to_push(type)
|
84
84
|
.merge(relationship.related_type =>
|
85
85
|
relationship.related_id_value)
|
@@ -92,7 +92,7 @@ module GlobalRegistry #:nodoc:
|
|
92
92
|
relationship_entity,
|
93
93
|
params: {
|
94
94
|
full_response: true,
|
95
|
-
fields: "#{relationship.
|
95
|
+
fields: "#{relationship.related_name}:relationship"
|
96
96
|
}
|
97
97
|
)
|
98
98
|
rescue RestClient::BadRequest => e
|
@@ -109,7 +109,7 @@ module GlobalRegistry #:nodoc:
|
|
109
109
|
)
|
110
110
|
return unless and_retry
|
111
111
|
raise GlobalRegistry::Bindings::RelatedEntityExistsWithCID,
|
112
|
-
"#{model.class.name}(#{model.id}) #{relationship.
|
112
|
+
"#{model.class.name}(#{model.id}) #{relationship.related_name}" \
|
113
113
|
':relationship already exists with client_integration_id(' \
|
114
114
|
"#{relationship.client_integration_id}). Will delete and retry."
|
115
115
|
end
|
@@ -11,7 +11,7 @@ module GlobalRegistry #:nodoc:
|
|
11
11
|
# rubocop:disable Metrics/MethodLength
|
12
12
|
# rubocop:disable Metrics/AbcSize
|
13
13
|
def push_global_registry_relationship_type
|
14
|
-
return unless global_registry_relationship(type).
|
14
|
+
return unless global_registry_relationship(type).ensure_type?
|
15
15
|
primary_entity_type_id = primary_associated_entity_type_id
|
16
16
|
related_entity_type_id = related_associated_entity_type_id
|
17
17
|
|
@@ -20,15 +20,15 @@ module GlobalRegistry #:nodoc:
|
|
20
20
|
'filters[between]' => "#{primary_entity_type_id},#{related_entity_type_id}"
|
21
21
|
)['relationship_types'].detect do |r|
|
22
22
|
r['relationship1']['relationship_name'] ==
|
23
|
-
global_registry_relationship(type).
|
23
|
+
global_registry_relationship(type).primary_name.to_s
|
24
24
|
end
|
25
25
|
unless rel
|
26
26
|
rel = GlobalRegistry::RelationshipType.post(
|
27
27
|
relationship_type: {
|
28
28
|
entity_type1_id: primary_entity_type_id,
|
29
29
|
entity_type2_id: related_entity_type_id,
|
30
|
-
relationship1: global_registry_relationship(type).
|
31
|
-
relationship2: global_registry_relationship(type).
|
30
|
+
relationship1: global_registry_relationship(type).primary_name,
|
31
|
+
relationship2: global_registry_relationship(type).related_name
|
32
32
|
}
|
33
33
|
)['relationship_type']
|
34
34
|
rename_relationship_entity_type(rel)
|
@@ -95,7 +95,7 @@ module GlobalRegistry #:nodoc:
|
|
95
95
|
def relationship_type_cache_key
|
96
96
|
"GlobalRegistry::Bindings::RelationshipType::#{global_registry_relationship(type).primary_type}::" \
|
97
97
|
"#{global_registry_relationship(type).related_type}::" \
|
98
|
-
"#{global_registry_relationship(type).
|
98
|
+
"#{global_registry_relationship(type).primary_name}"
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|