activerecord-multi-tenant icon indicating copy to clipboard operation
activerecord-multi-tenant copied to clipboard

Rails 7.1 - error when multi_tenant defined in abstract class

Open joshforbes opened this issue 1 year ago • 2 comments

After updating to Rails 7.1, I'm getting this error when running my tests:

TypeError:
       no implicit conversion of nil into String

I've tracked it down to this definition of multi_tenant in the parent abstract class:

image

I can confirm that MultiTenant.current_tenant is set. Moving the method directly to the subclass causes it to start working again. Removing the multi_tenant method will give me the expected invalid model (because the organization is nil).

I'm not seeing anything about this in the changelog... am I missing something?

joshforbes avatar Feb 26 '24 04:02 joshforbes

Did you ever find a solution to this, other than moving multi_tenant to the subclasses?

carldr avatar Jun 14 '24 14:06 carldr

@joshforbes @carldr I was also struggling with almost the same issue! Now I updated to Rails 7.1 by replacing the abstract class with a mix-in. The code is as follows:

module MultiTenantOrganization
  extend ActiveSupport::Concern

  included do
    multi_tenant :organization
    belongs_to :organization
  end
end


class Account < ApplicationRecord # Previously, an abstract class was inherited here
  include MultiTenantOrganization

  # account implementation...
end

dlwr avatar Jul 05 '24 09:07 dlwr