jekuno / milia

Easy multi-tenanting for Rails5 (or Rails4) + Devise
MIT License
341 stars 72 forks source link

Tenant models with String primary key(ID) instead Integer(ID) - Not working #82

Open NarasimhaReddyY opened 6 years ago

NarasimhaReddyY commented 6 years ago

Hello, Am using milia with my rails app. It was working pretty fine until i changed my models primary key data type to String instead of Integer.

While signup a new tenant, it's not creating new tenant and user, Instead it's raising Milia::Control::InvalidTenantAccess: no existing valid current tenant error.

I tried to figured out why this is happening, then i found this is causing while creating new tenant for first time.

Here is the code from lib/milia/base.rb

      def acts_as_universal_and_determines_account()
        include ::Milia::InviteMember
        has_and_belongs_to_many :tenants

        acts_as_universal()

        # validate that a tenant exists prior to a user creation
        before_create do |new_user|
          if Thread.current[:tenant_id].blank? ||
              !Thread.current[:tenant_id].kind_of?(Integer) ||
              Thread.current[:tenant_id].zero?

            raise ::Milia::Control::InvalidTenantAccess, "no existing valid current tenant"

          end
        end
      end

Here we can see that it's checking for Integer type tenant_id. What if we would like to use some other data type instead Integer. ?? Thanks ...!

dasibre commented 6 years ago

I'm having the same issue, using uuid's

NarasimhaReddyY commented 6 years ago

There is a open PR #73 to fix this, not yet merged.

dasibre commented 6 years ago

thats great