aware_support wroteNo need to have a separate PDF document for this, because it's really simple in Aware IM. But we will add an article on this to the How To document.
If you implement this in one database you need to:
- Define an object representing a Tenant
- For all objects that belong to the tenant add a reference to the Tenant that it belongs to, for example Account.Tenant
- The user object must have a reference to Tenant that it operates on behalf of - LoggedInSystemUser.Tenant
- For each object that belongs to some tenant add rules to initialise tenant from the tenant of the logged in user that created the object, for example:
IF Account.Tenant IS UNDEFINED Then
Account.Tenant = LoggedInSystemUser.Tenant
- Finally add protection rules to the object that belong to the tenant so that other tenants do not see it, for example:
IF Account.Tenant <> LoggedInSystemUser.Tenant Then
READ PROTECT Account FROM ALL EXCEPT System
Thank you for speedy reply. Your points are crystal clear, but there is one significant point that is missing for me and here it is.
So the Account object (table) is under Tenant. So it has a Parent (Tenant) / Child (Account) relationship.
Let's take that a step a bit further.
An Account also have "Order" object that is the child of the account and grand child of the tenant. And this hierarchy can go deeper with line item as following.
Tenant -> Account -> Order -> Line item.
So here is my question:
Database design # 1) Just the same way we referenced the Tenant to it child (Account), should we also reference the tenant to it's grand children, like Order and line item?
In this way, I'm still referencing each level to it's above parent to maintain the chain, but an extra reference to grand father for safety measure.
This allows me to work with Line Item level and have an immediate reference to it's Tenant with one jump. Like Tenant.LineItem
Database design # 2) Have the tenant reference ONLY in the first level below the tenant, which is the account. And then Order will reference to Account and line item would reference to Order? Going this way, then any time I need the tenant of the line item, I must walk up all the way through the hierarchy chain like.
Tenant.Account.Order.LineItem
But my problem with this style is, a lineitem or order are almost an orphan grand children with no grand father (tenant) reference to them.
From Aware's point of view and query speed and DB indexing for fast retrieval, Should I design my database in the way of # 1 or #2?
In my previous designs and work, Every Object under tenant, regardless the level, they all have reference to their Grand father to make sure every record in database has a reference to it's original tenant. But I wanted to run this by you and your vision.
Thank you kindly.