Returns

Caution: Validation can contain safeguards against invalid/malicious data,
and check permission levels (e.g. on Group). Therefore it is recommended
to only disable validation for very specific use cases.

Parameters

Returns

Get all database columns explicitly defined on a class in DataObject::$db and DataObject::$has_one. Resolves instances of CompositeDBField into the actual database fields, rather than the name of the
field which might not equate a database column.

Get all database columns explicitly defined on a class in DataObject::$db and DataObject::$has_one. Resolves instances of CompositeDBField into the actual database fields, rather than the name of the
field which might not equate a database column.

Parameters

$record

array|null $record This will be null for a new database record. Alternatively,
you can pass an array of field values. Normally this contructor is only used by
the internal systems that get objects from the database.

$isSingleton

boolean $isSingleton This this to true if this is a singleton() object, a stub
for calling methods. Singletons don't have their defaults set.

Returns

Copies the many_many and belongs_many_many relations from one object to
another instance of the name of object The destinationObject must be written to
the database already and have an ID. Writing is performed automatically when
adding the new relations.

Copies the many_many and belongs_many_many relations from one object to
another instance of the name of object The destinationObject must be written to
the database already and have an ID. Writing is performed automatically when
adding the new relations.

Parameters

$sourceObject

$sourceObject the source object to duplicate from

$destinationObject

$destinationObject the destination object to populate with the duplicated
relations

Returns

Set the ClassName attribute. Object::$class is also updated. Warning: This
will produce an inconsistent record, as the object instance will not
automatically switch to the new subclass. Please use DataObject::newClassInstance()
for this purpose, or destroy and reinstanciate the record.

Set the ClassName attribute. Object::$class is also updated. Warning: This
will produce an inconsistent record, as the object instance will not
automatically switch to the new subclass. Please use DataObject::newClassInstance()
for this purpose, or destroy and reinstanciate the record.

Parameters

$className

string $className The new ClassName attribute (a subclass of DataObject)

Returns

Create a new instance of a different class from this object's record. This is
useful when dynamically changing the type of an instance. Specifically, it
ensures that the instance of the class is a match for the className of the
record. Don't set the DataObject->class or DataObject->ClassName property manually before calling this method, as it
will confuse change detection.

Create a new instance of a different class from this object's record. This is
useful when dynamically changing the type of an instance. Specifically, it
ensures that the instance of the class is a match for the className of the
record. Don't set the DataObject->class or DataObject->ClassName property manually before calling this method, as it
will confuse change detection.

If the new class is different to the original class, defaults are populated
again because this will only occur automatically on instantiation of a
DataObject if there is no record, or the record has no ID. In this case, we do
have an ID but we still need to repopulate the defaults.

Parameters

$newClassName

string $newClassName The name of the new class

Returns

DataObjectThe new instance of the new class, The exact type will be of the class name
provided.

Returns

Get the translated user friendly plural name of this DataObject Same as
plural_name but runs it through the translation function Translation string is
in the form:
$this->class.PLURALNAME Example:
Page.PLURALNAME

Get the translated user friendly plural name of this DataObject Same as
plural_name but runs it through the translation function Translation string is
in the form: $this->class.PLURALNAME Example: Page.PLURALNAME

Returns

Standard implementation of a title/label for a specific record. Tries to find
properties 'Title' or 'Name', and falls back to the 'ID'. Useful to provide
user-friendly identification of a record, e.g. in errormessages or
UI-selections.

Standard implementation of a title/label for a specific record. Tries to find
properties 'Title' or 'Name', and falls back to the 'ID'. Useful to provide
user-friendly identification of a record, e.g. in errormessages or
UI-selections.

Overload this method to have a more specialized implementation, e.g. for an
Address record this could be:

Returns

Merges data and relations from another object of same class, without conflict
resolution. Allows to specify which dataset takes priority in case its not
empty. has_one-relations are just transferred with priority 'right'. has_many
and many_many-relations are added regardless of priority.

Merges data and relations from another object of same class, without conflict
resolution. Allows to specify which dataset takes priority in case its not
empty. has_one-relations are just transferred with priority 'right'. has_many
and many_many-relations are added regardless of priority.

Caution: has_many/many_many relations are moved rather than duplicated,
meaning they are not connected to the merged object any longer. Caution: Just
saves updated has_many/many_many relations to the database, doesn't write the
updated object itself (just writes the object-properties). Caution: Does not
delete the merged object. Caution: Does now overwrite Created date on the
original object.

Parameters

$rightObj

$obj DataObject

$priority

$priority String left|right Determines who wins in case of a conflict (optional)

$includeRelations

$includeRelations Boolean Merge any existing relations (optional)

$overwriteWithEmpty

$overwriteWithEmpty Boolean Overwrite existing left values with empty right
values. Only applicable with $priority='right'. (optional)

Returns

See

Event handler called before writing to the database. You can overload this to
clean up or otherwise process data before writing it to the database. Don't
forget to call parent::onBeforeWrite(), though!

Event handler called before writing to the database. You can overload this to
clean up or otherwise process data before writing it to the database. Don't
forget to call parent::onBeforeWrite(), though!

This called after $this->validate(), so you can be sure that your
data is valid.

Uses

Event handler called after writing to the database. You can overload this to
act upon changes made to the data after it is written. $this->changed will
have a record database. Don't forget to call parent::onAfterWrite(), though!

Event handler called after writing to the database. You can overload this to
act upon changes made to the data after it is written. $this->changed will
have a record database. Don't forget to call parent::onAfterWrite(), though!

Returns

Uses

Writes all changes to this object to the database.
- It will insert a record whenever ID isn't set, otherwise update.
- All relevant tables will be updated.
- $this->onBeforeWrite() gets called beforehand.
- Extensions such as Versioned will ammend the database-write to ensure that a
version is saved.

Writes all changes to this object to the database. - It will insert a record
whenever ID isn't set, otherwise update. - All relevant tables will be updated.
- $this->onBeforeWrite() gets called beforehand. - Extensions such as
Versioned will ammend the database-write to ensure that a version is saved.

Parameters

$showDebug

boolean $showDebug Show debugging information

$forceInsert

boolean $forceInsert Run INSERT command rather than UPDATE, even if record
already exists

Parameters

Get the class ancestry, including the current class name. The ancestry will
be returned as an array of class names, where the 0th element will be the class
that inherits directly from DataObject, and the last element will be the current
class.

Get the class ancestry, including the current class name. The ancestry will
be returned as an array of class names, where the 0th element will be the class
that inherits directly from DataObject, and the last element will be the current
class.

Parameters

Centerpiece of every data administration interface in Silverstripe, which
returns a FieldList suitable for a Form object. If not
overloaded, we're using DataObject::scaffoldFormFields() to automatically generate
this set. To customize, overload this method in a subclass or extended onto it
by using DataExtension->updateCMSFields().

Centerpiece of every data administration interface in Silverstripe, which
returns a FieldList suitable for a Form object. If not
overloaded, we're using DataObject::scaffoldFormFields() to automatically generate
this set. To customize, overload this method in a subclass or extended onto it
by using DataExtension->updateCMSFields().

Returns

Used for simple frontend forms without relation editing or TabSet
behaviour. Uses DataObject::scaffoldFormFields() by default. To customize, either
overload this method in your subclass, or extend it by DataExtension->updateFrontEndFields().

Used for simple frontend forms without relation editing or TabSet
behaviour. Uses DataObject::scaffoldFormFields() by default. To customize, either
overload this method in your subclass, or extend it by DataExtension->updateFrontEndFields().

Parameters

Returns

Overrides

Set the value of the field, using a casting object. This is useful when you
aren't sure that a date is in SQL format, for example. setCastedField() can also
be used, by forms, to set related data. For example, uploaded images can be
saved into the Image table.

Set the value of the field, using a casting object. This is useful when you
aren't sure that a date is in SQL format, for example. setCastedField() can also
be used, by forms, to set related data. For example, uploaded images can be
saved into the Image table.

Returns

Returns

Return the DBField object that represents the given field. This works
similarly to obj() with 2 key differences:
- it still returns an object even when the field has no value.
- it only matches fields and not methods
- it matches foreign keys generated by has_one relationships, eg, "ParentID"

Return the DBField object that represents the given field. This works
similarly to obj() with 2 key differences: - it still returns an object even
when the field has no value. - it only matches fields and not methods - it
matches foreign keys generated by has_one relationships, eg, "ParentID"

Uses

Add default records to database. This function is called whenever the
database is built, after the database tables have all been created. Overload
this to add default records when the database is built, but make sure you call
parent::requireDefaultRecords().

Add default records to database. This function is called whenever the
database is built, after the database tables have all been created. Overload
this to add default records when the database is built, but make sure you call
parent::requireDefaultRecords().

Needed to avoid getCMSFields being empty when customDatabaseFields overlooks
the inheritance chain of the $db array, where a child data object has no $db
array, but still needs to know the properties of its parent. This should be
merged into databaseFields or customDatabaseFields.

Returns

Get any user defined searchable fields labels that exist. Allows overriding
of default field names in the form interface actually presented to the user.

Get any user defined searchable fields labels that exist. Allows overriding
of default field names in the form interface actually presented to the user.

The reason for keeping this separate from searchable_fields, which would be a
logical place for this functionality, is to avoid bloating and complicating the
configuration array. Currently much of this system is based on sensible
defaults, and this property would generally only be set in the case of more
complex relationships between data object being required in the search
interface.

Generates labels based on name of the field itself, if no static property
self::field_labels exists.

Parameters

$includerelations

boolean $includerelations a boolean value to indicate if the labels returned
include relation fields

Returns

array|stringArray of all element labels if no argument given, otherwise the label of the
field

Comments

Comment policy: Please use comments for tips and corrections about the described
functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.