3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1262 Views |
-
BulkLoader and has_many relations

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?
-
Re: BulkLoader and has_many relations

17 March 2011 at 7:50pm Last edited: 18 March 2011 9:32am
Did you make any progress with this?
I have a similar requirement. -
Re: BulkLoader and has_many relations

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}'"
);
}
} -
Re: BulkLoader and has_many relations

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 http://silverstripe.org/data-model-questions/show/16221#post300697
| 1262 Views | ||
|
Page:
1
|
Go to Top |


