# Account model handles Tenant management
class Account < ApplicationRecord
  MAX_SUBDOMAIN_LENGTH = 20

  validates :name, :subdomain, presence: true
  validates_uniqueness_of :name, :subdomain, case_sensitive: false
  validates_length_of :subdomain, :name, maximum: MAX_SUBDOMAIN_LENGTH

end
```
:::

## Scope models
___

Now let's add users to `Account`. Here I am assuming to have an existing user model which is used for `Authentication`.
Similarly we can scope other models.

:::code-group
```ruby [db/migrate/random_number_add_account_to_users.rb]{3}
class AddAccountToUsers < ActiveRecord::Migration
  def up
    add_column :users, :account_id, :integer # if we have existing user set null to true then update the data using seed
    add_index  :users, :account_id
  end
end
```
```ruby [app/models/account.rb]{3}