我们面临两个问题,你能帮我们解决这个问题吗?
( 1)如何动态地指向POMM中的模式。例如,我有一个public模式,它存储所有用户的详细信息和与每个用户相关的私有模式。当用户登录到逻辑中是要读取public模式时,找到私有模式编号并将用户重定向到他的私有模式--我如何在http://www.postgresql.org/docs/9.1/static/ddl-schemas.html中实现这一点。在每个私有模式中,有多个表(例如雇员、一般数据/雇员工资数据等等)。
2)当我们有多个具有相同表结构(employee general / employee工资数据)的模式时,我们需要一个类来处理所有模式--现在每个表POMM生成一个类。
谢谢你的帮助。
发布于 2015-07-30 20:59:55
默认情况下,Pomm的模型管理器像使用名称空间一样使用每个模式,并使用它们的完全限定名schema.relation访问关系。
这里的想法是调整模型管理器,以便通过search_path环境变量来猜测模式。
您需要一个template模式,其中定义了所有模式中的所有公共关系。仅为此模式生成模型、结构和实体:
$ php vendor/bin/pomm pomm:generate:schema-all db_name template对于每个Model类,在构造函数中,只需设置没有模式信息的关系,如下所示:
class EmployeeModel extends Model
{
    public function __construct()
    {
        $this->structure = new EmployeeStructure;
        $this->flexible_entity_class = '\Test\TemplateSchema\Employee';
        $this->structure->setRelation('employee'); // <- add this line
    }
}现在,在您的代码中,只需设置search_path环境变量如下:
$pomm
    ->getDefaultSession()
    ->getConnection()
    ->executeAnonymousQuery(
        sprintf("SET search_path to %s, public", $schema)
    );
// Look in the employee table in the given schema
$employees = $pomm
    ->getDefaultSession()
    ->getModel('\DbName\Template\EmployeeModel')
    ->findAll()
    ;每次更改搜索路径时,Template模型文件都会指向不同模式中的表。
https://stackoverflow.com/questions/31722602
复制相似问题