When you duplicate a page in the Silverstripe Sitetree, related “has_one” Items are automatically copied, which is nice.
But if you have, lets say, multiple related images on that Page, those are not copied when you duplicate that Page.
After reading this discussion, i found out that it’s actually pretty easy to “fix” this.
This what i ended up with and seems to be working fine:
//assuming your page has the following related Dataobjects public static $has_many = array( 'Images' => 'MyImageDataObject' ); public static $many_many = array( 'Something' => 'AnotherPageTypeOrWhatever );
The following code would automatically duplicate the has_many related DataObjects
and just set the relation to the many_many Objects on the created page:
..as already suggested in the forum, i still think this would make a handy core feature, wouldn’t it?
Would be cool to globally specify relations to duplicate in the page-config with something like
public static $relations_to_copy = array( 'Images', 'Somehting' );