Skip to content

Commit ac891ac

Browse files
♻️ Model#global_id_method instead of Model#global_id_column
`Model.primary_key` is actually irrelevant to this feature, the only thing that matters is the model method. For composite keys, or primary keys not named "id", we still get the important value from `Model#id`, the only time we don't is when we need to use a non-PK column.
1 parent 03b4abd commit ac891ac

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

lib/global_id/identification.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def global_id_column(column_name = nil)
3636
end
3737
end
3838

39-
def global_id_column
40-
self.class.global_id_column || self.class.try(:primary_key) || :id
39+
def global_id_method
40+
self.class.global_id_column || :id
4141
end
4242

4343
# Returns the Global ID of the model.

lib/global_id/uri/gid.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def parse(uri)
7272
#
7373
# URI::GID.create('bcx', Person.find(5), database: 'superhumans')
7474
def create(app, model, params = nil)
75-
model_id_method = model.id.is_a?(Array) ? :id : model.global_id_column
76-
77-
build app: app, model_name: model.class.name, model_id: model.send(model_id_method), params: params
75+
build app: app, model_name: model.class.name, model_id: model.send(model.global_id_method), params: params
7876
end
7977

8078
# Create a new URI::GID from components with argument check.

test/models/person.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ class PersonUuid < Person
4141
def self.primary_key
4242
:uuid
4343
end
44-
45-
def uuid
46-
id
47-
end
4844
end
4945

5046
class Person::Scoped < Person

0 commit comments

Comments
 (0)