diff --git a/src/ORM/ManyManyThroughList.php b/src/ORM/ManyManyThroughList.php index bb783c578..f771e36a3 100644 --- a/src/ORM/ManyManyThroughList.php +++ b/src/ORM/ManyManyThroughList.php @@ -230,4 +230,13 @@ class ManyManyThroughList extends RelationList $joinClass = $this->manipulator->getJoinClass(); return Config::inst()->get($joinClass, 'db'); } + + /** + * @return string + */ + public function getJoinTable() + { + $joinClass = $this->manipulator->getJoinClass(); + return DataObject::getSchema()->tableName($joinClass); + } } diff --git a/tests/php/ORM/ManyManyThroughListTest.php b/tests/php/ORM/ManyManyThroughListTest.php index fa1801dfb..73b9b1507 100644 --- a/tests/php/ORM/ManyManyThroughListTest.php +++ b/tests/php/ORM/ManyManyThroughListTest.php @@ -6,6 +6,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\ManyManyThroughList; use SilverStripe\ORM\Tests\ManyManyThroughListTest\PolyItem; +use SilverStripe\ORM\Tests\ManyManyThroughListTest\PolyJoinObject; class ManyManyThroughListTest extends SapphireTest { @@ -261,4 +262,19 @@ class ManyManyThroughListTest extends SapphireTest ['Title' => 'New Item'], ], $objB2->Items()); } + + public function testGetJoinTable() + { + $joinTable = DataObject::getSchema()->tableName(PolyJoinObject::class); + /** @var ManyManyThroughListTest\PolyObjectA $objA1 */ + $objA1 = $this->objFromFixture(ManyManyThroughListTest\PolyObjectA::class, 'obja1'); + /** @var ManyManyThroughListTest\PolyObjectB $objB1 */ + $objB1 = $this->objFromFixture(ManyManyThroughListTest\PolyObjectB::class, 'objb1'); + /** @var ManyManyThroughListTest\PolyObjectB $objB2 */ + $objB2 = $this->objFromFixture(ManyManyThroughListTest\PolyObjectB::class, 'objb2'); + + $this->assertEquals($joinTable, $objA1->Items()->getJoinTable()); + $this->assertEquals($joinTable, $objB1->Items()->getJoinTable()); + $this->assertEquals($joinTable, $objB2->Items()->getJoinTable()); + } }