How to add a custom field to DataObject::get()?
Example: DataObject::get()->addSelectField("CONCAT('My', 'S', 'QL')");
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
How to add a custom field to DataObject::get()?
Example: DataObject::get()->addSelectField("CONCAT('My', 'S', 'QL')");
http://www.silverstripe.org/data-model-questions/show/21621
If you need them as actual DataObject instances, you can loop over them like this:
$query = new SQLQuery();
$query->setFrom('SomeTable');
$query->selectField("CONCAT('My', 'S', 'QL')");
$array = $query->execute();
$results = array();
// Convert them from simple array items to DataObject instances
foreach ($array as $row) {
$results[] = new YourDataObject($row);
}
return new ArrayList($results);
Thanks, this is what I ended up using. I was just hoping that there is an easier way to add a custom select field.