-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX many_many through should allow subclasses (#11230)
```php class HomePage extends Page { private static $many_many = [ 'HeroImages' => [ 'through' => PageImageLink::class, 'from' => 'Page', 'to' => 'Image', ] ]; } ``` ```php class PageImageLink extends DataObject { private static $has_one = [ 'Page' => SiteTree::class, 'Image' => Image::class, ]; } This fails because the linking object's relation class doesn't exactly match the owner. Sharing the linking objects across various entries in the ancestry should be a supported use case. Co-authored-by: Aaron Carlino <unclecheese@leftandmain.com>
- Loading branch information
1 parent
0f6d210
commit 50a0018
Showing
5 changed files
with
137 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/php/ORM/ManyManyThroughListTest/PseudoPolyJoinObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace SilverStripe\ORM\Tests\ManyManyThroughListTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataObject; | ||
|
||
/** | ||
* @property string $Title | ||
* @method TestObject Parent() | ||
* @method Item Child() | ||
*/ | ||
class PseudoPolyJoinObject extends DataObject implements TestOnly | ||
{ | ||
private static $table_name = 'ManyManyThroughListTest_PseudoPolyJoinObject'; | ||
|
||
private static $db = [ | ||
'Title' => 'Varchar', | ||
'Sort' => 'Int', | ||
]; | ||
|
||
private static $has_one = [ | ||
'Parent' => TestObject::class, | ||
'Child' => Item::class, | ||
]; | ||
|
||
private static $default_sort = '"Sort" ASC'; | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/php/ORM/ManyManyThroughListTest/TestObjectSubclass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace SilverStripe\ORM\Tests\ManyManyThroughListTest; | ||
|
||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\ORM\ManyManyThroughList; | ||
|
||
/** | ||
* Basic parent object | ||
* | ||
* @property string $Title | ||
* @method ManyManyThroughList Items() | ||
*/ | ||
class TestObjectSubclass extends TestObject implements TestOnly | ||
{ | ||
private static $table_name = 'ManyManyThroughListTest_TestObjectSubclass'; | ||
|
||
private static $db = [ | ||
'Title' => 'Varchar' | ||
]; | ||
|
||
private static $many_many = [ | ||
'MoreItems' => [ | ||
'through' => PseudoPolyJoinObject::class, | ||
'from' => 'Parent', | ||
'to' => 'Child', | ||
] | ||
]; | ||
} |