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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

BulkLoader and has_many relations

Go to End

4 Posts   1963 Views


Community Member, 545 Posts

26 February 2011 at 10:12am

I'm just wondering how you define has_many relations using the BulkLoader.

I have a csv that contains UPC's, descriptions, etc for clothing items. I've set up one DataObject with all the common info for a product such as Name, Color etc. and a has_many relation to another DataObject that contains the UPC and Size. How do I ensure that has_many relations link correctly out of one csv.

Or Am I better off just importing into one table and trying to filter out duplicate style numbers in other interfaces in my app?


Community Member, 35 Posts

17 March 2011 at 7:50pm

Edited: 18/03/2011 9:32am

Did you make any progress with this?
I have a similar requirement.


Community Member, 545 Posts

18 March 2011 at 8:58am

Yeah I ended up just flipping the way I was thinking about it. I uploaded the CSV to a UPC bulkloader which would than create the individual items. I think My problem was I was thinking it heretically instead of as a two way relation. Because if each item has_many UPCs then each UPC has_one Item. Just means using a lot of dot notion to build the Item.

class ClothingCsvBulkLoader extends CsvBulkLoader {
	public $columnMap = array(
		"ClothingStyleNo" => "ClothingItem.ClothingStyleNo",
		"ClothingMasterID" => "ClothingItem.ClothingMasterID",
		"ClothingSize" => "ClothingItem.ClothingSize",
		"ClothingPrice" => "ClothingItem.ClothingPrice",
		"ClothingMSRP" => "ClothingItem.ClothingMSRP",
		"ClothingDescription" => "ClothingItem.ClothingDescription",
		"ClothingColor" => "ClothingItem.ClothingColor",
		"ClothingCollection" => "ClothingItem.ClothingCollection",
		"ClothingProductGroup" => "ClothingItem.ClothingProductGroup",
		"ClothingFabric" => "ClothingItem.ClothingFabric",
		"ClothingGarmentWeight" => "ClothingItem.ClothingGarmentWeight",
		"ClothingPackageWeight" => "ClothingItem.ClothingPackageWeight",
		"ClothingPackageType" => "ClothingItem.ClothingPackageType",
		"ClothingWashCare" => "ClothingItem.ClothingWashCare",
		"ClothingMade" => "ClothingItem.ClothingMade",
		"ClothingDesigned" => "ClothingItem.ClothingDesigned",
		"ClothingCollectionBook" => "ClothingItem.ClothingCollectionBook",
		//Define Folders
		"WebReadyFolderID" => "ClothingItem.WebReadyFolderID",
		"HiResFolderID" => "ClothingItem.HiResFolderID",
		"MarketingImageFolderID" => "ClothingItem.MarketingImageFolderID",
		"PackageImageFolderID" => "ClothingItem.PackageImageFolderID",
		// Define ClothingUPC Fields
		"UPC" => "UPC",
		"ItemID" => "ItemID",
		"Size" => "Size",
		"ItemStyleNo" => "ItemStyleNo"
   public $duplicateChecks = array(
      'UPC' => 'UPC'
   public $relationCallbacks = array(
      'ClothingItem.ClothingStyleNo' => array(
         'relationname' => 'ClothingItem',
         'callback' => 'getStyleByNumber'
   static function getStyleByNumber(&$obj, $val, $record) {
      $SQL_val = Convert::raw2sql($val);
      return DataObject::get_one(
         'ClothingItem', "ClothingStyleNo = '{$SQL_val}'"


Community Member, 35 Posts

18 March 2011 at 9:28am

Thanks for the update. This is good to know.

I was able to resolve my problem via directly populating the database ( its data from another SS database). The issue I had I resolved as follows