Merge branch '5.2' into 5

This commit is contained in:
github-actions 2024-04-13 14:23:22 +00:00
commit 3e1b5e6452

View File

@ -57,7 +57,8 @@ class PolymorphicHasManyList extends HasManyList
public function setForeignRelation(string $relationName): static public function setForeignRelation(string $relationName): static
{ {
Deprecation::notice('5.2.0', 'Will be replaced with a parameter in the constructor'); Deprecation::notice('5.2.0', 'Will be replaced with a parameter in the constructor');
$this->dataQuery->where(["\"{$this->relationForeignKey}\"" => $relationName]); $foreignRelationColumn = DataObject::getSchema()->sqlColumnForField($this->dataClass, $this->relationForeignKey);
$this->dataQuery->where([$foreignRelationColumn => $relationName]);
$this->dataQuery->setQueryParam('Foreign.Relation', $relationName); $this->dataQuery->setQueryParam('Foreign.Relation', $relationName);
return $this; return $this;
} }
@ -102,8 +103,9 @@ class PolymorphicHasManyList extends HasManyList
// For queries with multiple foreign IDs (such as that generated by // For queries with multiple foreign IDs (such as that generated by
// DataList::relation) the filter must be generalised to filter by subclasses // DataList::relation) the filter must be generalised to filter by subclasses
$classNames = Convert::raw2sql(ClassInfo::subclassesFor($foreignClass)); $classNames = Convert::raw2sql(ClassInfo::subclassesFor($foreignClass));
$foreignClassColumn = DataObject::getSchema()->sqlColumnForField($dataClass, $this->classForeignKey);
$this->dataQuery->where(sprintf( $this->dataQuery->where(sprintf(
"\"{$this->classForeignKey}\" IN ('%s')", "$foreignClassColumn IN ('%s')",
implode("', '", $classNames) implode("', '", $classNames)
)); ));
} }