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 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

Setting a default value to parent fields

Go to End

2 Posts   1380 Views


Community Member, 12 Posts

20 August 2015 at 3:53am

Edited: 20/08/2015 5:32am


I have a products class extending from Page and PageSections extending from DataObject. Each page can have many Page Sections and each Page Section can belong to many Pages.

public static $belongs_many_many = array(
		"PageSections" => "PageSection"

//Page Section
public static $many_many = array(
    	'Pages' => 'Page'

Product gets it's parent fields.

What I'm trying to accomplish is: each time I create a product, associate an specific existing Page Section by default.

Either via the Product model or calling the specific Page Section in the Product template.

Any suggestions?

Thank you for your help.


Community Member, 419 Posts

21 August 2015 at 1:08am

//Page Section
private static $many_many = [
	'Pages' => 'Page',
	'Products' => 'Product'