rails / globalid

Identify app models with a URI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoMethodError: undefined method `unscoped' for Class

antulik opened this issue · comments

locate_many does not work properly when different objects are passed.

GlobalID::Locator.locate_many ['gid://app/User/3', 'gid://app/Custom::Item/74592']

The issue User is active_record model and responds to :unscoped, Custom::Item is custom model and does not support :unscoped method.

As a result the above code returns
NoMethodError: undefined method 'unscoped' for Custom::Item:Class

but works if you swap the order of objects.

Related
https://github.com/rails/globalid/pull/73/files

as a workaround who needs it, I've added this class method to Custom::Item class

def self.unscoped
  if block_given?
    yield
  else
    self
  end
end

Thanks @antulik. 2d4bc2d should fix your issue 😁