Skip to content

Commit

Permalink
Merge branch '5.2' into 5
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 13, 2024
2 parents 39c9e0d + 6743de4 commit 3e1b5e6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ORM/PolymorphicHasManyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function getForeignRelation(): ?string
public function setForeignRelation(string $relationName): static
{
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);
return $this;
}
Expand Down Expand Up @@ -102,8 +103,9 @@ public function __construct($dataClass, $foreignField, $foreignClass)
// For queries with multiple foreign IDs (such as that generated by
// DataList::relation) the filter must be generalised to filter by subclasses
$classNames = Convert::raw2sql(ClassInfo::subclassesFor($foreignClass));
$foreignClassColumn = DataObject::getSchema()->sqlColumnForField($dataClass, $this->classForeignKey);
$this->dataQuery->where(sprintf(
"\"{$this->classForeignKey}\" IN ('%s')",
"$foreignClassColumn IN ('%s')",
implode("', '", $classNames)
));
}
Expand Down

0 comments on commit 3e1b5e6

Please sign in to comment.