Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » BulkLoader and has_many relations

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

Page: 1
Go to End
Author Topic: 1490 Views
  • zenmonkey
    Avatar
    Community Member
    527 Posts

    BulkLoader and has_many relations Link to this post

    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?

  • CraftsMan
    Avatar
    Community Member
    35 Posts

    Re: BulkLoader and has_many relations Link to this post

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

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: BulkLoader and has_many relations Link to this post

    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}'"
    );
    }
    }

  • CraftsMan
    Avatar
    Community Member
    35 Posts

    Re: BulkLoader and has_many relations Link to this post

    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 http://silverstripe.org/data-model-questions/show/16221#post300697

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