I am new to SilverStripe and I want to perform a simple query using SilverStripe functions (I don't want to use raw SQL). I want to get all the columns' names of the product table. So far, I didn't find anything useful in the SilverStripe documentation. I appreciate any suggestion.
Asked
Active
Viewed 162 times
1 Answers
0
You have to understand that the Silverstripe $db
(Data Model / ORM) and database columns are not always in sync. If you delete a $db
attribute, the column will still exist in your database, but no longer in your ORM. Source
Assuming you want the current ORM-attributes, you can simply use, for a Dataobject $record
:
$attributes = $record->toMap();
Even more attributes (even inherited attributes) can be collected by using the schema:
$schema = \SilverStripe\ORM\DataObject::getSchema();
$allFields = $schema->fieldSpecs($record);
$columns = array_keys($allFields);

Terry
- 304
- 1
- 7