php - POMM Postgresql multiple schema and global class -
we facing 2 issues, solved
1) how point dynamically schema in pomm. example have public
schema stores users details , private schema related each user. when user logs in logic read public
schema, find private schema number , redirect user private schema - how can achieve in pomm (http://www.postgresql.org/docs/9.1/static/ddl-schemas.html). inside each private schema there multiple tables (example employees general data / employees salary data , on).
2) when have multiple schemas same table structure (employee general / employee salary data) need 1 class working schemas - each table pomm generates 1 class.
thank help.
by default, pomm's model manager uses each schema namespace , access relations using qualified name schema.relation
.
the idea here tweak model manager schema can guessed search_path
environment variable.
you need template
schema relations in common in schemas defined. generate models, structures , entities schema only:
$ php vendor/bin/pomm pomm:generate:schema-all db_name template
for each model class, in constructor, set relation without schema information this:
class employeemodel extends model { public function __construct() { $this->structure = new employeestructure; $this->flexible_entity_class = '\test\templateschema\employee'; $this->structure->setrelation('employee'); // <- add line } }
now, in code, set search_path
environment variable this:
$pomm ->getdefaultsession() ->getconnection() ->executeanonymousquery( sprintf("set search_path %s, public", $schema) ); // in employee table in given schema $employees = $pomm ->getdefaultsession() ->getmodel('\dbname\template\employeemodel') ->findall() ;
every time change search path, template
model files point tables in different schemas.
Comments
Post a Comment