Hi, I'm a total newb.
Bit stumped on my first project.
I have a DO class, Bike. It needs to have X images, so it has a has_many relationship to a class, BikeImage, that just extends File, and declares the has_one relationship back to bike.
All good. The DB looks right - I have a join table between File and Bike.
I installed dataobjectmanager and uploadify for the back-end to be nice. And it mostly does, very nice in fact, apart from the crucial relationship between Bike and Image - the join table doesn't get populated when I update an existing Bike and give it an image (using 'import' which I'm assuming is correct).
I've implemented the form both using modeladmin and through a class extending page with getCMSFields, but I get the same thing. Either if I add an image first through Files & Images, or if I upload it from the CRUD form and import it.
The requests looks good (editing the first bike in the db):
http://mydoman.local/admin/bikeadmin/Bike/1/EditForm?action_doSave=Save
with form data
. Title:Some bike
. Description:this is a great bike
. NumberOfGears:27
. WheelSize:26
. FromPrice:800
. AttachedFiles:
. UploadFolderID_Form_EditForm_AttachedFiles:1
. NewFolder_Form_EditForm_AttachedFiles:
. ImportFolderID_Form_EditForm_AttachedFiles:
. ImportFiles[]:46
. AttachedFiles[]:46
. ID:1
46 is the image that is in the file table that I selected. No errors. Just don't get why it won't update the DB.
Some code…
My page class:
class BikesPage extends Page {
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Bikes", new DataObjectManager(
$this,
'Bikes',
'Bike',
array(//some props),
'getCMSFields_forPopup'
));
$f->push( new MultipleFileUploadField('AttachedFiles','Upload several files') );
return $f;
}
}
...
My DO:
class Bike extends DataObject {
static $db = array(
//some props
);
static $has_many = array(
'BikeImages' => 'BikeImage'
);
public function getCMSFields() {
$fields = new FieldSet();
//push some props
$fields->push( new MultipleFileUploadField('AttachedFiles','Upload several files') );
return $fields;
}
}
BikeImage
class BikeImage extends File {
static $has_one = array (
'Image' => 'Bike'
);
}
I'm stumped. It looks like it should work. But I guess I'm missing something key.
Thanks very much.