Merge pull request #8140 from open-sausages/pulls/4.1/through-belongs-issue

BUG Backport bugfix for belongs_many_many with many_many through.
This commit is contained in:
Daniel Hensby 2018-06-06 11:18:07 +01:00 committed by GitHub
commit ffc2eeea05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -982,9 +982,17 @@ class DataObjectSchema
if (!$otherManyMany) {
return null;
}
foreach ($otherManyMany as $inverseComponentName => $nextClass) {
if ($nextClass === $parentClass) {
return $inverseComponentName;
foreach ($otherManyMany as $inverseComponentName => $manyManySpec) {
// Normal many-many
if ($manyManySpec === $parentClass) {
return $inverseComponentName;
}
// many-many through, inspect 'to' for the many_many
if (is_array($manyManySpec)) {
$toClass = $this->hasOneComponent($manyManySpec['through'], $manyManySpec['to']);
if ($toClass === $parentClass) {
return $inverseComponentName;
}
}
}
return null;

View File

@ -19,6 +19,7 @@ class Item extends DataObject implements TestOnly
];
private static $belongs_many_many = [
'Objects' => 'SilverStripe\\ORM\\Tests\\ManyManyThroughListTest\\TestObject.Items'
// Intentionally omit parent `.Items` specifier to ensure it's not mandatory
'Objects' => TestObject::class,
];
}