mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: castingHelper failed to find many_many_extraFields data (fixes #4661)
This commit is contained in:
parent
8947bb0245
commit
7a81372294
@ -1786,6 +1786,12 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
$extraFields = $this->manyManyExtraFieldsForComponent($componentName) ?: array();
|
||||
$result = ManyManyList::create($componentClass, $table, $componentField, $parentField, $extraFields);
|
||||
|
||||
|
||||
// Store component data in query meta-data
|
||||
$result = $result->alterDataQuery(function($query) use ($extraFields) {
|
||||
$query->setQueryParam('Component.ExtraFields', $extraFields);
|
||||
});
|
||||
|
||||
if($this->model) $result->setDataModel($this->model);
|
||||
|
||||
$this->extend('updateManyManyComponents', $result);
|
||||
@ -2683,6 +2689,28 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function castingHelper($field) {
|
||||
if ($fieldSpec = $this->db($field)) {
|
||||
return $fieldSpec;
|
||||
}
|
||||
|
||||
// many_many_extraFields aren't presented by db(), so we check if the source query params
|
||||
// provide us with meta-data for a many_many relation we can inspect for extra fields.
|
||||
$queryParams = $this->getSourceQueryParams();
|
||||
if (!empty($queryParams['Component.ExtraFields'])) {
|
||||
$extraFields = $queryParams['Component.ExtraFields'];
|
||||
|
||||
if (isset($extraFields[$field])) {
|
||||
return $extraFields[$field];
|
||||
}
|
||||
}
|
||||
|
||||
return parent::castingHelper($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given field exists in a database column on any of
|
||||
* the objects tables and optionally look up a dynamic getter with
|
||||
|
@ -911,6 +911,16 @@ class DataObjectTest extends SapphireTest {
|
||||
$this->assertEmpty($fields);
|
||||
}
|
||||
|
||||
public function testCastingHelper() {
|
||||
$team = $this->objFromFixture('DataObjectTest_Team', 'team1');
|
||||
|
||||
$this->assertEquals('Varchar', $team->castingHelper('Title'), 'db field wasn\'t casted correctly');
|
||||
$this->assertEquals('HTMLVarchar', $team->castingHelper('DatabaseField'), 'db field wasn\'t casted correctly');
|
||||
|
||||
$sponsor = $team->Sponsors()->first();
|
||||
$this->assertEquals('Int', $sponsor->castingHelper('SponsorFee'), 'many_many_extraFields not casted correctly');
|
||||
}
|
||||
|
||||
public function testSummaryFieldsCustomLabels() {
|
||||
$team = $this->objFromFixture('DataObjectTest_Team', 'team1');
|
||||
$summaryFields = $team->summaryFields();
|
||||
|
Loading…
Reference in New Issue
Block a user