BUGFIX: DBComposite doesn't allow arbitrary property assignment

To be more consistent with `ViewableData`, whose `setField()` method will fallback on [assigning properties arbitrarily](https://github.com/silverstripe/silverstripe-framework/blob/4/src/View/ViewableData.php#L213), `DBComposite` shouldn't bail out of `setField` when the field specified isn't in the record.

Arbitrary property assignment is particularly important in injection.

```yaml
SilverStripe\ORM\FieldType\DBComposite:
  dependencies:
    myService: %$Service
```

Right now, that fails, because `$obj->myService = Service` invokes `__set()` which calls `setField()` which refuses the assignment when `myService`is not in the record.
This commit is contained in:
Aaron Carlino 2017-07-27 17:25:29 +12:00 committed by GitHub
parent 697798b464
commit 3ef9ca69d1

View File

@ -240,8 +240,9 @@ abstract class DBComposite extends DBField
{
$this->objCacheClear();
// Skip non-db fields
// Non-db fields get assigned as normal properties
if (!$this->hasField($field)) {
$this->$field = $value;
return $this;
}