[support] Issues with pdo abstraction with 1:many data
Metzler, David
metzlerd at evergreen.edu
Thu Jan 16 21:02:53 UTC 2014
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 at drupal.org [mailto:support-bounces at drupal.org] On Behalf Of Jeff Greenberg
Sent: Thursday, January 16, 2014 11:40 AM
To: support at drupal.org
Subject: [support] Issues with pdo abstraction with 1:many data
I have the following code:
$query = db_query('SELECT * FROM table1 t1 LEFT JOIN table2 t2 ON t1.id<http://t1.id> = t2.id<http://t2.id>');
$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.
--
---
drupal.org/user/367108<http://drupal.org/user/367108>
linkedin.com/in/jeffrgreenberg<http://linkedin.com/in/jeffrgreenberg>
accidentalcoder.com<http://accidentalcoder.com> / ayendesigns.com<http://ayendesigns.com>
@accidentalcoder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20140116/e169c751/attachment.html
More information about the support
mailing list