Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Default data structures on build

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

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

Page: 1
Go to End
Author Topic: 1195 Views
  • Hamish
    Avatar
    Community Member
    712 Posts

    Default data structures on build Link to this post

    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.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Default data structures on build Link to this post

    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();
       }
    }

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Default data structures on build Link to this post

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

    1195 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.