Using Postgres 8.1.x and the Cake 1.2x branch

Howdy, I've been checking out Cake for the past few days, moving an
existing app over, and i'm really, REALLY pleased. I do have a few
stumbling blocks, though, and have been saving up some questions.
Here's the first:

I have several tables that inherit from another (parent_table).
Normally, when selecting from parent_table based on the PKey (where
the data is actually in one of several child tables), the name of the
child table is not included. One needs to do something like the
following:

SELECT p.relname, pt.name, pt.this, pt,that
FROM parent_table AS pt
LEFT JOIN pg_class p ON pt.tableoid = p.oid
WHERE pt.id = $id;

The gist of it is that the tableoid column holds a foreign key
pointing back to pg_class, which holds the name of the child table.
The tableoid is a system column and wouldn't normally be found by Cake
(it isn't in information_schema.columns), though there's nothing
special about selecting it.

My existing app relies heavily on PL/PgSQL, PL/Perl, and PL/Python
functions and selecting data from these inherited tables is all
handled on the backend. But, in the interest of doing things the cake
way, I thought I'd see if I could get this to work. I created a model
for the pg_class table and added it to the $hasMany array for the
ParentTable model:

class ParentTable extends AppModel
{
        var $name = 'ParentTable';

        var $belongsTo = array(
                'SomethingElse',
                'AnotherModel',
                'PgClass' =>
                        array(
                                'className'     => 'PgClass',
                                'foreignKey'    => 'tableoid',
                                'fields'                => 'relname'
            )
        );
...
}

class PgClass extends AppModel
{
        var $name = 'PgClass';
        var $useDbConfig = 'pg_catalog';
        var $useTable = 'pg_class';
        var $primaryKey = 'oid';
        var $hasMany = Array('ParentTable');
}

Because pg_class resides in the pg_catalog schema I needed to add a
new configuration for it in DATABASE_CONFIG and set PgClass to use it.
However, this caused the entire app to fail miserably, with the models
complaining that none of the tables exist. I updated every other model
with var $useDbConfig = 'default' but everything remains quite broken:

Warning (512): SQL Error: ERROR:  relation
"some_table_in_public_schema" does not exist [CORE/cake/libs/model/
datasources/dbo_source.php, line 440

So, though models give the option to change the schema, is there any
way to protect the default schema for all associated models? Does
changing the schema for one do the same for every other one? Is it not
possible to associate models across schemas? Is the problem something
else entirely?

If there's no solution to this I can always fall back on PL/PgSQL
functions. However, that would mean having to make direct queries,
rather than using Cake's find*() methods.

brian


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to