0

I have a specific database (called account_base) for my account :

class Account < ActiveRecord::Base

  establish_connection :account_base
  
  ...
end

I have user from app rails database :

class User < ActiveRecord::Base
  belongs_to :account
end

When I try User.first.account this work fine.

Now I want get all users with account => state == Account::STATE_ACTIVED, I try :

User.includes(:account).where('accounts.state' => Account::STATE_ACTIVED)

but I have this error :

Mysql2::Error: Table 'RAILS_DATABASE_NAME.accounts' doesn't exist

I try with where('account_base.accounts.state' to specify the bd, but not works

Any idea ?

Matrix
  • 3,458
  • 6
  • 40
  • 76
  • I am not sure it is possible if those are two separate database clusters, examples you provided will work for separate schemas in one cluster though – mr. Holiday Sep 03 '21 at 17:15
  • 1
    This would require the use of foreign data wrapper. Are you sure you really want to design it like this? – max Sep 03 '21 at 17:17
  • How do you design multi web site with only one account for each otherwise ? – Matrix Sep 05 '21 at 00:20
  • @max maybe I can duplicate state in user main database, but I have to update in each database project the state if value is update in one of them, it's not realy good too... any idea? – Matrix Sep 07 '21 at 11:53
  • Depends entirely on you requirements. You should probably look into the authentication as a service architecture which you can build with doorkeeper or use third party solutions such as auth0. – max Sep 07 '21 at 11:59

0 Answers0