mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW: Added DataObject::getQueriedDatabaseFields() as faster alternative to toMap()
API: CompositeDBField::setValue() may be passed an object as its second argument, in addition to array. These changes provide a 15% - 20% performance improvement, and as such justify an small API change in the 3.0 branch. It will likely affect anyone who has created their own composite fields, which is fortunately not all that common.
This commit is contained in:
parent
e13ce9b98f
commit
eb583c5f14
5
docs/en/changelogs/3.0.6.md
Normal file
5
docs/en/changelogs/3.0.6.md
Normal file
@ -0,0 +1,5 @@
|
||||
# 3.0.6 (Not yet released)
|
||||
|
||||
## Upgrading
|
||||
|
||||
* If you have created your own composite database fields, then you shoulcd amend the setValue() to allow the passing of an object (usually DataObject) as well as an array.
|
@ -730,6 +730,18 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all currently fetched database fields.
|
||||
*
|
||||
* This function is similar to toMap() but doesn't trigger the lazy-loading of all unfetched fields.
|
||||
* Obviously, this makes it a lot faster.
|
||||
*
|
||||
* @return array The data as a map.
|
||||
*/
|
||||
public function getQueriedDatabaseFields() {
|
||||
return $this->record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a number of fields on this object, given a map of the desired changes.
|
||||
*
|
||||
|
@ -118,7 +118,7 @@ interface CompositeDBField {
|
||||
* parameter.
|
||||
*
|
||||
* @param DBField|array $value
|
||||
* @param array $record Map of values loaded from the database
|
||||
* @param DataObject|array $record An array or object that this field is part of
|
||||
* @param boolean $markChanged Indicate wether this field should be marked changed.
|
||||
* Set to FALSE if you are initializing this field after construction, rather
|
||||
* than setting a new value.
|
||||
|
@ -103,6 +103,11 @@ class Money extends DBField implements CompositeDBField {
|
||||
}
|
||||
|
||||
public function setValue($value, $record = null, $markChanged = true) {
|
||||
// Convert an object to an array
|
||||
if($record && $record instanceof DataObject) {
|
||||
$record = $record->getQueriedDatabaseFields();
|
||||
}
|
||||
|
||||
// @todo Allow resetting value to NULL through Money $value field
|
||||
if ($value instanceof Money && $value->exists()) {
|
||||
$this->setCurrency($value->getCurrency(), $markChanged);
|
||||
|
@ -374,7 +374,7 @@ class ViewableData extends Object implements IteratorAggregate {
|
||||
}
|
||||
|
||||
$valueObject = Object::create_from_string($castConstructor, $fieldName);
|
||||
$valueObject->setValue($value, ($this->hasMethod('toMap') ? $this->toMap() : null));
|
||||
$valueObject->setValue($value, $this);
|
||||
|
||||
$value = $valueObject;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user