\VirtualFieldIndex
Adds a new field to the mysql table which can hold the result of a "virtual field" (i.e. method call on the model or relation).
Usage (config.yml):
Product:
extensions:
- VirtualFieldIndex
VirtualFieldIndex
vfi_spec:
Product:
Price:
Type: simple
Source: sellingPrice
DependsOn: BasePrice
DBField: Currency
Categories:
Type: list
DependsOn: all
Source:
- ParentID
- ProductCategories.ID
The above will create two new fields on Product: VFI_Price and VFI_Categories.
These will be updated whenever the object is changed and can be triggered via
a build task (dev/tasks/BuildVFI).
The categories index will contain the merging of results from ParentID and
ProductCategories.ID in the form of a comma-delimited list.
NOTE: having multiple sources doesn't equate with Type=list always. That's
just the default. Type=list means the output is a list. A single source could
also return an array and that would be a list as well.
- Author: Mark Guinn <mark@adaircreative.com>
Synopsis
- // constants
- const TYPE_LIST = 'list';
- const TYPE_SIMPLE = 'simple';
- const DEPENDS_ALL = 'all';
- const DEPENDS_NONE = 'none';
- // members
- private static array $vfi_spec = ;
- private static bool $fast_writes_enabled = false;
- protected bool $isRebuilding = false;
- public static boolean $disable_building = false;
- // methods
- public static array get_classes_with_vfi()
- public static array get_extra_config()
- public static array get_vfi_spec()
- public static void build()
- public void rebuildVFI()
- public string getVFIFieldName()
- public array|false getVFISpec()
- public string|array|SS_List getVFI()
- public string|array|SS_List VFI()
- protected static string encode_list()
- protected static array decode_list()
- protected static mixed get_value()
- public void onBeforeWrite()
Hierarchy
Extends
- DataExtension
Constants
Name | Value |
---|---|
TYPE_LIST | 'list' |
TYPE_SIMPLE | 'simple' |
DEPENDS_ALL | 'all' |
DEPENDS_NONE | 'none' |
Members
private
- $fast_writes_enabled — bool
- $vfi_spec — array
protected
- $isRebuilding — bool
public
- $disable_building
Methods
protected
- decode_list()
- encode_list()
- get_value() — This is largely borrowed from DataObject::relField, but adapted to work with many-many and has-many fields.
public
- VFI() — Template version
- build() — Rebuilds any vfi fields on one class (or all). Doing it in chunks means a few more queries but it means we can handle larger datasets without storing everything in memory.
- getVFI()
- getVFIFieldName()
- getVFISpec()
- get_classes_with_vfi()
- get_extra_config() — Define extra db fields and indexes.
- get_vfi_spec() — Return a normalized version of the vfi definition for a given class
- onBeforeWrite() — Trigger rebuild if needed
- rebuildVFI() — Rebuild all vfi fields.