3062 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 845 Views |
-
Adding relations to ComponentSet only saves last one

14 November 2009 at 9:07am Last edited: 14 November 2009 9:08am
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}'");
if($file){
$photo = new Photo();
$photo->ImageID = $file->ID;
$existingPhotos->add($photo);
}
}
| 845 Views | ||
|
Page:
1
|
Go to Top |

