I am using Doctrine 1.2 under the Zend framework to run my database queries. I have two tables that I query using inner join, like so:
$q = Doctrine_Query::create()
->from('My_Model_MaterialsFromDb g')
->innerJoin('t.My_Model_TeachingMaterials t');
->where('g.id= ?', $id)
$result = $q->fetchArray();
Basically, the first table (materialsFromDb) contains a list of all of the teaching materials that I use for a lesson. The second one (teachingMaterials) has the details of the materials themselves.
When I run this query, here’s what the result invariably looks like:
Array
(
[0] => Array
(
[id] => 1
[activityId] => 1
[materialId] => 2
[My_Model_Materials] => Array
(
[id] => 2
[title] => My Groovy Material
[materialType] => Worksheet
[description] => This is my groovy material. It looks really cool.
[filename] => Groovy Material.doc
[uploaderId] => 1
[uploadDate] => 2012-02-16
)
)
)
Is there any way I can run a doctrine query to “flatten” this to a single array? Is the result looking like this because both tables have a primary key called “id”? Having this multidimensional array as my result is a real pain to say the least.
according to the Doctrine 1.2 docs, this is exaclty what’s supposed to happen.
try…
or…
this one should return something like