File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,11 @@ def locate(gid, options = {})
162
162
model_class = gid . model_class
163
163
model_class = model_class . includes ( options [ :includes ] ) if options [ :includes ]
164
164
165
- model_class . find gid . model_id
165
+ if model_class . global_id_column
166
+ model_class . find_by model_class . global_id_column => gid . model_id
167
+ else
168
+ model_class . find gid . model_id
169
+ end
166
170
end
167
171
168
172
def locate_many ( gids , options = { } )
Original file line number Diff line number Diff line change @@ -55,15 +55,15 @@ class GlobalIDCreationTest < ActiveSupport::TestCase
55
55
assert_equal Person ::Child . find ( @person_namespaced_gid . model_id ) , @person_namespaced_gid . find
56
56
assert_equal PersonModel . find ( @person_model_gid . model_id ) , @person_model_gid . find
57
57
assert_equal CompositePrimaryKeyModel . find ( @cpk_model_gid . model_id ) , @cpk_model_gid . find
58
- assert_equal ConfigurableKeyModel . find ( @ckm_model_gid . model_id ) , @ckm_model_gid . find
58
+ assert_equal ConfigurableKeyModel . find_by ( external_id : @ckm_model_gid . model_id ) , @ckm_model_gid . find
59
59
end
60
60
61
61
test 'find with class' do
62
62
assert_equal Person . find ( @person_gid . model_id ) , @person_gid . find ( only : Person )
63
63
assert_equal Person . find ( @person_uuid_gid . model_id ) , @person_uuid_gid . find ( only : Person )
64
64
assert_equal PersonModel . find ( @person_model_gid . model_id ) , @person_model_gid . find ( only : PersonModel )
65
65
assert_equal CompositePrimaryKeyModel . find ( @cpk_model_gid . model_id ) , @cpk_model_gid . find ( only : CompositePrimaryKeyModel )
66
- assert_equal ConfigurableKeyModel . find ( @ckm_model_gid . model_id ) , @ckm_model_gid . find ( only : ConfigurableKeyModel )
66
+ assert_equal ConfigurableKeyModel . find_by ( external_id : @ckm_model_gid . model_id ) , @ckm_model_gid . find ( only : ConfigurableKeyModel )
67
67
end
68
68
69
69
test 'find with class no match' do
Original file line number Diff line number Diff line change @@ -13,7 +13,11 @@ def primary_key
13
13
:id
14
14
end
15
15
16
- def find ( external_id )
16
+ def find ( _id )
17
+ raise ".find is not supported for ConfigurableKeyModel"
18
+ end
19
+
20
+ def find_by ( external_id :)
17
21
new external_id : external_id , id : "id-value"
18
22
end
19
23
end
You can’t perform that action at this time.
0 commit comments