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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Default data structures on build


Go to End


3 Posts   1914 Views

Avatar
Hamish

Community Member, 712 Posts

18 February 2009 at 4:41pm

Hi all,

Is it possible to provide a set of sample data (ie, as yml) that will automatically be loaded on dev/build? The test runner does this, just wondering if it is possible for normal projects.

This would be great for populating certain objects when the database is built.

Avatar
ajshort

Community Member, 244 Posts

18 February 2009 at 5:54pm

requireDefaultRecords() is run on each DataObject when the DataObject is built - so you could just do something like:

public function requireDefaultRecords() {
	if(!DataObject::get_one('PageType')) {
		$pageType = new PageType();
		
		// ...
		
		$pageType->write();
	}
}

Avatar
Hamish

Community Member, 712 Posts

18 February 2009 at 9:25pm

Cheers AJ, that's the sort of thing I'm looking for.