Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Pre-loading a data store with initial data

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

Page: 1
Go to End
Author Topic: 1270 Views
  • Judge
    Avatar
    Community Member
    79 Posts

    Pre-loading a data store with initial data Link to this post

    Is there a way to automatically load up a data store (a datamodel table) with information when it is created? I require a country-selection field and figured it would be good idea to put it into a separate module for reuse. The countries would be stored in the database, and so it would be ideal for the table to be pre-populated as soon as the module is installed.

    The country data will be in XML files initially, to make it easier to handle international characters.

    Unless, of course, such a module already exists?

    -- Jason

    Edit: of course, an ideal module would contain an arbitrary number of nested and linked regions of any arbitrary type, for use in different ways. For example, to be able to define the UK, its countries, then its regions, then its counties (of which there are several sets, depending on how you define "county"), and its postal code areas (overlapping and not fully enclosed within counties) etc. would be tremendously useful. That would also link to GIS outline shapes, yet another level of usefulness. That is probably a step further than I need to go now, especially being a newbie to SS.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Pre-loading a data store with initial data Link to this post

    Hiya,

    If you add the method requireDefaultRecords() to your model class, it will be called when the database is built, after the tables have been created.

    I.e. you could write a script that loads data from an XML file when your database is created. Note that Sapphire comes with Spyc for reading YAML documents - this could be a good way to load up a simple dataset like regions.

    Incidentally, I've already done something similar to your arbitrary linked regions system for a project. Using the http://doc.silverstripe.org/doku.php?id=hierarchy extension it's quite easy to implement. We haven't gone quite as far as added a GIS layer over the top (partly because the regions were not always strictly geographic), but it's quite achievable.

  • Judge
    Avatar
    Community Member
    79 Posts

    Re: Pre-loading a data store with initial data Link to this post

    Thanks Hamish,

    The GIS layer I was thinking of probably doesn't involve much more than a large text field to hold CSV polygon data for the outlines (more likely multiple polygons, so broken areas and holes in areas can be drawn). I've done something similar in another project, with the polygon data being pulled out and converted into Google Maps polygon layers with roll-overs. There was no need to split the individual points out into separate data items, so storing it is very easy.

    I'll have a look at YAML. It's a term I've seen a lot, but never really explored it.

    -- Jason

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