Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Linking a page to multiple page types


Go to End


3 Posts   1106 Views

Avatar
Apc204

Community Member, 12 Posts

23 April 2015 at 11:59pm

I have a structure in my new website where I need to link an 'Application' to multiple 'Products' (and show them on the Application page as thumbnails). The way I would have done this in the past is to create a many to many relationship such as this (In Application.php)

private static $many_many = array(
        'Products' => 'Product'
    );

Then I would choose the products to link to each Application by using a Grid FIeld.

However in this case i have multiple different types of Product e.g Product1 Product2 Product3.

I would like to do something such as

private static $many_many = array(
        'Products' => array( 'Product1', 'Product2', 'Product3')
    );

Then the grid field should allow me to search products of all three types. But this doesn't seem to work the way I wanted it to.

If anyone has done something similar in the past that could point me in the right direction, it would be greatly appreciated.

Many Thanks,
Adam.

Avatar
Devlin

Community Member, 344 Posts

24 April 2015 at 9:39pm

If the classes 'Product1', 'Product2' and 'Product3' would extend a class 'Product', then you could continue to use $many_many = ['Products' => 'Product'];

Avatar
Apc204

Community Member, 12 Posts

24 April 2015 at 9:41pm

Thanks Devlin, I worked out that I could do this last night and it works great :)

Cheers for the reply.