Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Adding relations to ComponentSet only saves last one

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

Page: 1
Go to End
Author Topic: 998 Views
  • MDrollette
    Community Member
    10 Posts

    Adding relations to ComponentSet only saves last one Link to this post

    I am using a CsvBulkLoader to import a ton of DataObjects. These objects have a has_many relation of photo's. In the csv source the photos are stored as filenames paths in seperate fields. I have this method that gets called on each of those fields to hopefully add the photos to the has_many relation. It almost works, but it seems to only save the very last photo... any ideas why it doesn't append the photo objects ?

    class CarPartCsvBulkLoader extends CsvBulkLoader {
    public $columnMap = array(
    'dvid' => 'DVID',
    'vehicle_price' => 'Price',
    'vehicle_year' => 'Year',
    'popup_vehicle_a' => '->importPhoto',
    'popup_vehicle_b' => '->importPhoto',

    static function importPhoto(&$obj, $val, $record) {
    $existingPhotos = $obj->Photos();

    $filename = 'assets/CarPartImages/'.$val;
    $file = DataObject::get_one('File', "Filename = '{$filename}'");
    $photo = new Photo();
    $photo->ImageID = $file->ID;

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.