mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX #5362: Fixed duplicate removal on DataObject:get() with join argument for all databases. (from r103588)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112150 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1e925a9e91
commit
712680a5e8
@ -1470,7 +1470,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$limit,
|
$limit,
|
||||||
"INNER JOIN \"$table\" ON \"$table\".\"$componentField\" = \"$componentBaseClass\".\"ID\"" // join
|
"INNER JOIN \"$table\" ON \"$table\".\"$componentField\" = \"$componentBaseClass\".\"ID\"" // join
|
||||||
);
|
);
|
||||||
array_unshift($query->select, "\"$table\".*");
|
|
||||||
|
foreach((array)$this->many_many_extraFields($componentName) as $extraField => $extraFieldType) {
|
||||||
|
$query->select[] = "\"$table\".\"$extraField\"";
|
||||||
|
}
|
||||||
|
|
||||||
if($filter) $query->where[] = $filter;
|
if($filter) $query->where[] = $filter;
|
||||||
if($join) $query->from[] = $join;
|
if($join) $query->from[] = $join;
|
||||||
@ -1687,15 +1690,19 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$candidateManyMany = $SNG_candidate->stat('belongs_many_many');
|
$candidateManyMany = $SNG_candidate->stat('belongs_many_many');
|
||||||
|
|
||||||
// Find the relation given the class
|
// Find the relation given the class
|
||||||
|
$relationName = null;
|
||||||
if($candidateManyMany) foreach($candidateManyMany as $relation => $relatedClass) {
|
if($candidateManyMany) foreach($candidateManyMany as $relation => $relatedClass) {
|
||||||
if($relatedClass == $class) {
|
if($relatedClass == $class) {
|
||||||
$relationName = $relation;
|
$relationName = $relation;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$extraFields = $SNG_candidate->stat('many_many_extraFields');
|
if($relationName) {
|
||||||
if(isset($extraFields[$relationName])) {
|
$extraFields = $SNG_candidate->stat('many_many_extraFields');
|
||||||
return $extraFields[$relationName];
|
if(isset($extraFields[$relationName])) {
|
||||||
|
return $extraFields[$relationName];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2640,13 +2647,17 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
|
|
||||||
if($join) {
|
if($join) {
|
||||||
$query->from[] = $join;
|
$query->from[] = $join;
|
||||||
if(DB::getConn() instanceof MySQLDatabase || DB::getConn() instanceof SQLite3Database) {
|
// In order to group by unique columns we have to group by everything listed in the select
|
||||||
// TODO: This needs to be resolved for all databases
|
foreach($query->select as $field) {
|
||||||
$query->groupby[] = reset($query->from) . ".\"ID\"";
|
// Identify columns with aliases, and ignore the alias. Making use of the alias in
|
||||||
/* this needs to be fixed - this doesn't work when you add additional fields from other tables into the mix.
|
// group by was causing problems when those queries were subsequently passed into
|
||||||
$fields = $this->databaseFields();
|
// SQLQuery::unlimitedRowCount.
|
||||||
foreach(array_keys($fields) as $field) $query->groupby[] = "\"$field\"";
|
if(preg_match('/^(.*)\s+AS\s+(\"[^"]+\")\s*$/', $field, $matches)) {
|
||||||
*/
|
$query->groupby[] = $matches[1];
|
||||||
|
// Otherwise just use the field as is
|
||||||
|
} else {
|
||||||
|
$query->groupby[] = $field;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user