I'm in the process of migrating a database from MySQL to PostgreSQL and am using CakePHP to access the data. The normal model methods (find, delete, create, etc), seem to work as expected, but when I run custom queries using the query method, it doesn't seem to populate the resulting array how I'd expect.
For example, this code when run with CakePHP with MySQL as the database:
$results = $this->Table1->query('SELECT Table1.*, Table2.* FROM Table1 LEFT JOIN Table2 USING (Field)');
Produces the following array
array(
array('Table1' => array(<Table1Result1>), 'Table2' => array(<Table2Result1>))
array('Table1' => array(<Table1Result2>), 'Table2' => array(<Table2Result2>))
...
array('Table1' => array(<Table1ResultN>), 'Table2' => array(<Table2ResultN>))
)
When I run a similar query using PostgreSQL as the database, I get the following array:
array(
array(0 => array(<Table1and2Result1Combined>))
array(0 => array(<Table1and2Result2Combined>))
...
array(0 => array(<Table1and2ResultNCombined>))
)
Is there a way to get the PostgreSQL result to be returned in the same way as the MySQL one?
$this->Table1->query('SELECT Table1.*, Table2.* FROM Table1 LEFT JOIN Table2 USING (Field)');- It'd be in your interest to actually use cake instead of cheating and using query. Query is not intended to be used for queries that can easily be performed using standard methods. Any internal changes to cake (like your use of the Table__Field convention used for deconstructing fields in that driver) will mean your code breaks in the future.