Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 909799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:56:26+00:00 2026-05-15T16:56:26+00:00

Suppose a column client_id is ubiquitous through out our database, and for a given

  • 0

Suppose a column client_id is ubiquitous through out our database, and for a given session or request, we will be ‘in the context’ of a client the whole time.

Is there a way to simulate having each client’s data stored in a separate database, while keeping them in the same table for simpler database-management ? What I want is similar to a default scope, but since it will change for every request, it cant’ be fixed at load-time.

  # invoices table data
  # -------------------
  # id       client_id     amount
  # 1        1             100.00
  # 2        2             100.00
  with_client( Client.find(1) ) do
     Invoices.all      # finds only invoice 1
     Invoices.find(2)  # finds nothing or raises
  end 

How can I do this with ActiveRecord, or at what points could I surgically alter AR to affect this behavior ?

Extra points: Id like to prevent the updating of this client_id column – it should be fixed at create-time

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:56:27+00:00Added an answer on May 15, 2026 at 4:56 pm

    There is a presentation here that discusses multi-tenanted applications. It has some interesting ideas to utilise database schemas, particularly for postgres.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose a database table has a column Name which is defined as key for
Suppose I have a database table that has a timedate column of the last
Suppose I have a table called Companies that has a DepartmentID column. There's also
I need to return contents of an xml column in sql server to client
Suppose that I have an enum column on a table and I want users
Suppose I have a collection of Pages that are ordered by a column called
Suppose I have a GridView on the page. GridView has edit column enabled and
Suppose I have a tags table with two columns: tagid and contentid . Each
Suppose I have a text file with data separated by whitespace into columns. I
Suppose your git history looks like this: 1 2 3 4 5 1–5 are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.