Skip to content

Instantly share code, notes, and snippets.

@pjbeardsley
Created July 11, 2012 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjbeardsley/3090603 to your computer and use it in GitHub Desktop.
Save pjbeardsley/3090603 to your computer and use it in GitHub Desktop.
fRecordSet.php.patch
Index: fRecordSet.php
===================================================================
--- fRecordSet.php (revision 71)
+++ fRecordSet.php (working copy)
@@ -1638,20 +1638,26 @@
if (isset($relationship['join_table'])) {
$table_to_join = $relationship['join_table'];
- $column_to_join = $relationship['join_table'] . '.' . $relationship['join_column'];
+ $column_to_join = $relationship['join_column'];
} else {
$table_to_join = $related_table;
- $column_to_join = $related_table . '.' . $relationship['related_column'];
+ $column_to_join = $relationship['related_column'];
}
+ $table_to_join_alias = $table_to_join;
+ if ($table_to_join == $table) {
+ $table_to_join_alias = $table_to_join . '_1';
+ }
+
$params = array($db->escape(
- "SELECT count(*) AS flourish__count, %r AS flourish__column FROM %r INNER JOIN %r ON %r = %r WHERE ",
+ "SELECT count(*) AS flourish__count, %r AS flourish__column FROM %r INNER JOIN %r AS %r ON %r = %r WHERE ",
$table_and_column,
$table,
$table_to_join,
+ $table_to_join_alias,
$table_and_column,
- $column_to_join
+ $table_to_join_alias . '.' . $column_to_join
));
$params = $this->addWhereParams($db, $schema, $params);
$params[0] .= $db->escape(' GROUP BY %r', $table_and_column);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment