From 314bc0dba5d27bed336a52b66534f5c596a8a1c3 Mon Sep 17 00:00:00 2001 From: Tyler Willingham <171991+tylerwillingham@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:04:14 -0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20`Model#global=5Fid=5Fmetho?= =?UTF-8?q?d`=20instead=20of=20`Model#global=5Fid=5Fcolumn`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- lib/global_id/identification.rb | 4 ++-- lib/global_id/uri/gid.rb | 4 +--- test/models/person.rb | 4 ---- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/global_id/identification.rb b/lib/global_id/identification.rb index eead1a1..70513a7 100644 --- a/lib/global_id/identification.rb +++ b/lib/global_id/identification.rb @@ -36,8 +36,8 @@ def global_id_column(column_name = nil) end end - def global_id_column - self.class.global_id_column || self.class.try(:primary_key) || :id + def global_id_method + self.class.global_id_column || :id end # Returns the Global ID of the model. diff --git a/lib/global_id/uri/gid.rb b/lib/global_id/uri/gid.rb index f0f6012..0b46591 100644 --- a/lib/global_id/uri/gid.rb +++ b/lib/global_id/uri/gid.rb @@ -70,9 +70,7 @@ def parse(uri) # # URI::GID.create('bcx', Person.find(5), database: 'superhumans') def create(app, model, params = nil) - model_id_method = model.id.is_a?(Array) ? :id : model.global_id_column - - build app: app, model_name: model.class.name, model_id: model.send(model_id_method), params: params + build app: app, model_name: model.class.name, model_id: model.send(model.global_id_method), params: params end # Create a new URI::GID from components with argument check. diff --git a/test/models/person.rb b/test/models/person.rb index d851ad1..a74ac59 100644 --- a/test/models/person.rb +++ b/test/models/person.rb @@ -41,10 +41,6 @@ class PersonUuid < Person def self.primary_key :uuid end - - def uuid - id - end end class Person::Scoped < Person