BUG Backport bugfix for belongs_many_many with many_many through.

Partial backport of #7928
Fixes #8131
This commit is contained in:
Damian Mooyman 2018-06-06 09:43:04 +12:00
parent 2bceabe454
commit 0aa13da0d9
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
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,
];
}