mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Fixed UploadField->managesRelation() when no record is set
This commit is contained in:
parent
f75537b589
commit
a0d583291c
@ -501,9 +501,8 @@ class UploadField extends FileField {
|
|||||||
$record = $this->getRecord();
|
$record = $this->getRecord();
|
||||||
$fieldName = $this->getName();
|
$fieldName = $this->getName();
|
||||||
return (
|
return (
|
||||||
$record->has_one($fieldName)
|
$record
|
||||||
|| $record->has_many($fieldName)
|
&& ($record->has_one($fieldName) || $record->has_many($fieldName) || $record->many_many($fieldName))
|
||||||
|| $record->many_many($fieldName)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,6 +375,29 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testManagesRelation() {
|
||||||
|
$record = $this->objFromFixture('UploadFieldTest_Record', 'record1');
|
||||||
|
|
||||||
|
$field = new UploadField('ManyManyFiles');
|
||||||
|
$this->assertFalse($field->managesRelation(), 'False if no record is set');
|
||||||
|
|
||||||
|
$field = new UploadField('NoRelationField');
|
||||||
|
$field->setRecord($record);
|
||||||
|
$this->assertFalse($field->managesRelation(), 'False if no relation found by name');
|
||||||
|
|
||||||
|
$field = new UploadField('HasOneFile');
|
||||||
|
$field->setRecord($record);
|
||||||
|
$this->assertTrue($field->managesRelation(), 'True for has_one');
|
||||||
|
|
||||||
|
$field = new UploadField('HasManyFiles');
|
||||||
|
$field->setRecord($record);
|
||||||
|
$this->assertTrue($field->managesRelation(), 'True for has_many');
|
||||||
|
|
||||||
|
$field = new UploadField('ManyManyFiles');
|
||||||
|
$field->setRecord($record);
|
||||||
|
$this->assertTrue($field->managesRelation(), 'True for many_many');
|
||||||
|
}
|
||||||
|
|
||||||
protected function getMockForm() {
|
protected function getMockForm() {
|
||||||
return new Form(new Controller(), 'Form', new FieldList(), new FieldList());
|
return new Form(new Controller(), 'Form', new FieldList(), new FieldList());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user