Would this work for has_one through?
adambedford opened this issue · 1 comments
adambedford commented
Would this work for a User relation that doesn't have an account_id
but instead is has_one :account, through: :account_membership
?
i.e. Could the tenant be derived from an association rather than a foreign_key column?
e.g.
class Account < ApplicationRecord
has_many :account_memberships
has_many :users, through: :account_memberships, dependent: :destroy
end
class AccountMembership < ApplicationRecord
belongs_to :account
belongs_to :user
end
class User < ApplicationRecord
has_one :account_membership
has_one :account, through: :account_membership
end
excid3 commented
When you add acts_as_tenant :account
, it adds a belongs_to :account
behind the scenes. For that reason, you have to have an account_id
column on any models you add acts_as_tenant
to.