How can I use acts_as_tenant for a grandchild of Account? (Child works fine)

My AccountSetting model is a child of account. And AccountSetting has its own child called SettingDeet, eg:

Account, has many:
  AccountSettings, has_many:

One level down works fine:
AccountSetting belongs_to Account, and acts_as_tenant :account.
Account has_many AccountSettings

So creating an `account_setting` in a controller automatically assigns the scoped Account, eg, `account_setting.account_id` = ``

What does not work however is the next level down...

SettingDeet belongs_to AccountSettings, and acts_as_tenant :account_setting.
AccountSetting has_many SettingDeets.

The tenant scoping is not working, when a setting_deet is created, its account_setting_id is set to the grandparent's id (the account), not the parent's id (account_setting).

I assume some additional config somewhere is needed to implement a new current_account_setting variable, similar to how current_user and current_account are created?

Any tips where/how to do that would be appreciated.

Tim Dowling
Have you added  "acts_as_tenant(:account)" to the model? It's in the scoping model section of the docs -
Yes, in the "child" model I have
    acts_as_tenant :account

And in the "grandchild" model I have
    acts_as_tenant :CHILDMODEL

But I think may see the issue.. it looks like JSP OTB assumes the only tenant parent class is Account - see last line here:

# app/controllers/concerns/set_current_request_details.rb
  def set_request_details  # included  in ApplicationController, e.g., all controllers
    Current.request_id = request.uuid
    Current.user_agent = request.user_agent
    Current.ip_address = request.ip
    Current.user = current_user

    # Account may already be set by the AccountMiddleware
    Current.account ||= account_from_domain || account_from_subdomain || account_from_session || fallback_account

    set_current_tenant(Current.account)  ### HERE ###

Anyone know how to get  a GRAND-CHILD of Account to acts_as_tenant for a CHILD of Account?

You’re not receiving notifications from this thread.
© 2021 GoRails, LLC