mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
commit
ffc2eeea05
@ -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