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

Import CSV without duplicating relations


Go to End


706 Views

Avatar
justin_t_brown

Community Member, 22 Posts

10 September 2015 at 8:17am

Edited: 10/09/2015 8:50am

I have a model, ProgramClass, for which I'd like to be able use the CSV import functionality to load data. I am able to do so, BUT what happens is any relations (ie. has_one) are duplicated. Here is the model:

<?php
class ProgramClass extends DataObject {

  static $singular_name = "Scheduled Class";

  static $plural_name = "Scheduled Classes";

  static $db = array(
    'InviteOnly' => 'Boolean',
    'AgeYoungestYear' => 'Int',
    'AgeYoungestMonth' => 'Int',
    'AgeOldestYear' => 'Int',
    'AgeOldestMonth' => 'Int',
    'StartingTime' => 'Time',
    'EndingTime' => 'Time',
    'NumberOfClasses' => 'Int',
    'Days' => 'MultiEnum(array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))',
    'Price' => 'Currency'
  );

  static $has_one = array(
    'Level' => 'Level',
    'Session' => 'ProgramSession',
    'Program' => 'Program'
  );
}

When I use the CSV import function as visible below in the bottom left corner:

It seems to work, except that it create duplicates of the Program DataObject, as you can see here:

There should only be one instance each of Mighty Mights and Advanced TRAC. My question is, how do I use CSV import without duplicating relations?

For reference here is the spreadsheet I'm using to export CSVs https://docs.google.com/spreadsheets/d/1Qn6nNHmkQFfNm1Y-CQhTI2-fDiN-rFqeJlv8WSmbDTs/edit?usp=sharing

Many thanks :)
Justin

P.S. - I should also mention I've attempted to extend CsvBulkLoader for ProgramClass, as demonstrated in the Silverstripe Developer Guides, but with no luck.