EzDevInfo.com

Pomm

PHP Object Model Manager for Postgresql

POMM Postgresql multiple schema and global class

We are facing 2 issues, could you help us get this solved

1) how to point dynamically to a schema in POMM. Example i have a public schema which stores all the users details and the private schema related to each user. When user logs in the logic is to read the public schema, find the private schema number and redirect the user to his private schema - how can i achieve this in POMM (http://www.postgresql.org/docs/9.1/static/ddl-schemas.html). Inside each private schema there are multiple tables (example employees general data / employees salary data and so on).

2) When we have multiple schemas with same table structure (employee general / employee salary data) we need one class for working with all schemas - now for each table POMM generates one class.

Thank you for the help.


Source: (StackOverflow)

Tree structure with hydrated model in Pomm-project

I have simple database table which implements tree structure via parent_id attribute. Something like this:

+----+------+-----------+
| id | name | parent_id |
+----+------+-----------+
|  1 | test | null      |
+----+------+-----------+
|  2 | tes2 | 1         |
+----+------+-----------+
|  3 | tes3 | 2         |
+----+------+-----------+
|  4 | tst  | 2         |
+----+------+-----------+

I want to obtain PHP object with tree structure. So object Category will have property subcategories, which will be list of Category objects and so on. I want to obtain this object directly from PostgreSQL database via recursive sql query with Pomm. The goal is not to traverse obtained data and build such object in PHP. I want straight process PostreSQL -> Pomm -> Object.

As for now, I get what I want by only in first level. So first level Category has subcategories, which is list of Category entities. However next level (depth 2) has no subcatogories.

So far I have this:

$sql = <<<SQL
with recursive
cat as (select c.* FROM :category c where parent_id is null),
subcat as (
select c.* from :category c join cat on c.parent_id=cat.id
union all
select c.* from :category c join subcat on c.parent_id=subcat.id
)
select :projection from cat cc, subcat
where cc.id=subcat.parent_id
group by :group_fields
SQL;

$projection = $this->createProjection()
    ->setField('subcategories', 'array_agg(subcat)', 'public.category[]');
$sql = strtr($sql, [
        ':category' => $this->structure->getRelation(),
        ':projection' => $projection->formatFieldsWithFieldAlias('cc'),
        ':group_fields' => $this->createProjection()->formatFields('cc'),
]);

My question if this is possible with Pomm and if yes, how?


Source: (StackOverflow)

Advertisements

How does this class know what table to query?

http://pomm.coolkeums.org/documentation/manual-1.2#findwhere

It is possible to use it directly because we are in a Map class hence Pomm knows what table and fields to use in the query.

It says that because we are in Map class Pomm knows what table to query. How does it know what table I want to query?


Source: (StackOverflow)

How do I load a PHP Class?

I use Pomm 1.1.4 and I cannot load the class. Here it says Fatal error: Class 'Pomm\Connection\Database' not found in /users/ilhanna/public_html/api/v1/Pomm-1.1.4/Pomm/Service.php on line 38 There is nothing on line 38, just a comment. My code to load the class is

require_once 'Pomm-1.1.4/Pomm/Service.php';
# Using the constructor
$service = new Pomm\Service(array(
  'db_one' => array(
    'dsn' => 'pgsql://username:password@localhost:5432/databasename'
  )
  ));

I am missing something I think.


Source: (StackOverflow)