silverstripe-framework/tests/php/ORM/ManyManyThroughListTest/PolyItem.php
Damian Mooyman 257ff69e32 API Implement many_many through polymorphic (from only) (#7928)
* API Support many_many through polymorphic relations (from side only)
Fixes #7911
Fixes #3136

* Add extra docs and allow optional arguments

* ENHANCEMENT Enable quiet to be turned off

* BUG Fix issue with manymanythroughlist duplication
2018-03-22 10:26:25 +13:00

37 lines
883 B
PHP

<?php
namespace SilverStripe\ORM\Tests\ManyManyThroughListTest;
use Generator;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
class PolyItem extends DataObject implements TestOnly
{
private static $table_name = 'ManyManyThroughListTest_PolyItem';
private static $db = [
'Title' => 'Varchar'
];
private static $has_many = [
'JoinObject' => PolyJoinObject::class . '.Items',
];
/**
* Placeholder for missing belongs_many_many for polymorphic relation
*
* @todo Make this work for belongs_many_many
* @return Generator|DataObject[]
*/
public function Objects()
{
foreach ($this->JoinObject() as $object) {
$objectParent = $object->Parent();
if ($objectParent && $objectParent->exists()) {
yield $objectParent;
}
}
}
}