mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Backport bugfix for belongs_many_many with many_many through.
Partial backport of #7928 Fixes #8131
This commit is contained in:
parent
2bceabe454
commit
0aa13da0d9
@ -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;
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user