Nope fetchAllAssoc() will not do that. A result set from a query is independent of table structure. The db driver doesn’t know which columns came from t1
vs. t2, so it can’t do what you are asking. They are collapsed into a recordset (table of data) by the query before the results are returned.
You will need to walk the results of the fetch and organize the resulting array yourself.
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org]
On Behalf Of Jeff Greenberg
Sent: Thursday, January 16, 2014 11:40 AM
To: support@drupal.org
Subject: [support] Issues with pdo abstraction with 1:many data
I have the following code:
$msg = $query->fetchAllAssoc('id');
Since it is 1:many data, I would expect
id 1
another t1 field
another t1 field
t2 value 1
more t2 from that row
t2 value 2
more t2 from that row
id 2
But I only get 1 t2 row for each t1. If I do the same query (without the fetchAllAssoc) in mysql I get the expected results.
--
---
@accidentalcoder