ORM dot notation with many_many and belongs_many_many relationships

I figured it out in the end, you don’t add the dot notation to the many_many, just to the belongs_many_many:

ServicePage.php
namespace MyNamespace;
use SilverStripe\Assets\Image;
class ServicePage extends Page
{
    private static $many_many = [  
        'ProjectImages' => Image::class,
    ];
}

MyImageExtension.php
namespace MyNamespace;
class MyImageExtension extends DataExtension
{
    private static $belongs_many_many = [
        'ServicePages' => ServicePage::class . '.ProjectImages',
    ];
}
1 Like