class - How to use model with multiple identical tables, for data isolation? -


i writing simple saas application small construction companies use , trying achieve mid-level data isolation having each company have own unique data tables aren't shared.

this nice in case where {group_id} clause missing, other group data won't exposed.

i able use command builder create these tables dynamically, prefixing them group number grp_37645_projects.

but stuck on how use model classes table names change.

after login, want set table names. these won't change users aren't allowed part of more 1 group.

i have read changing tablename, static function, , have read little creating classes on fly, neither option detailed or complete.

i know touches on single table inheritance, once again, every example use little different scenario.

do have recommended solution setting tablenames dynamically?

add logic tablename:

namespace app\models;  use yii\db\activerecord;  class project extends activerecord {     /**      * @return string name of table associated activerecord class.      */     public static function tablename()     {         //some logic getting current "group_id" current user         $current_group_id = \yii::$app->user->identity->group_id;         return 'grp_'.$current_group_id.'_projects';     } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -