NEW Add getJoinTable to MMTL

This commit is contained in:
Daniel Hensby 2018-05-11 16:04:22 +01:00
parent fe5a271634
commit 1a57c7c1d0
No known key found for this signature in database
GPG Key ID: D8DEBC4C8E7BC8B9
2 changed files with 25 additions and 0 deletions

View File

@ -230,4 +230,13 @@ class ManyManyThroughList extends RelationList
$joinClass = $this->manipulator->getJoinClass(); $joinClass = $this->manipulator->getJoinClass();
return Config::inst()->get($joinClass, 'db'); return Config::inst()->get($joinClass, 'db');
} }
/**
* @return string
*/
public function getJoinTable()
{
$joinClass = $this->manipulator->getJoinClass();
return DataObject::getSchema()->tableName($joinClass);
}
} }

View File

@ -6,6 +6,7 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ManyManyThroughList; use SilverStripe\ORM\ManyManyThroughList;
use SilverStripe\ORM\Tests\ManyManyThroughListTest\PolyItem; use SilverStripe\ORM\Tests\ManyManyThroughListTest\PolyItem;
use SilverStripe\ORM\Tests\ManyManyThroughListTest\PolyJoinObject;
class ManyManyThroughListTest extends SapphireTest class ManyManyThroughListTest extends SapphireTest
{ {
@ -261,4 +262,19 @@ class ManyManyThroughListTest extends SapphireTest
['Title' => 'New Item'], ['Title' => 'New Item'],
], $objB2->Items()); ], $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());
}
} }