Merge pull request #7525 from open-sausages/pulls/4.0/databasefields-docs

Update changelogs to include notes about database_fields
This commit is contained in:
Damian Mooyman 2017-10-30 17:36:16 +13:00 committed by GitHub
commit c04dfd9ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1178,20 +1178,15 @@ class MyAddressField extends
}
```
### `DataObject::database_fields` or `DataObject::db` {#dataobject-db-database-fields}
### Removed `DataObject::database_fields` or `DataObject::db` {#dataobject-db-database-fields}
These methods have been updated to include base fields (such as ID, ClassName, Created, and LastEdited), as
well as composite DB fields.
The methods `DataObject::database_fields()`, `DataObject::custom_database_fields()` and `DataObject::db()` have
been removed.
`DataObject::database_fields` does not have a second parameter anymore, and can be called directly on an object
or class. E.g. `Member::database_fields()`.
If user code requires the list of fields excluding base fields, then use custom_database_fields instead, or
make sure to call `unset($fields['ID']);` if this field should be excluded.
Instead, to get all database fields for a dataobject, including base fields (such as ID, ClassName, Created, and LastEdited), use `DataObject::getSchema()->databaseFields($className, $aggregate = true)`.
To omit the base fields, pass a value of `false` as the `$aggregate` parameter, e.g. `DataObject::getSchema()->databaseFields(Member::class, false)`.
`DataObject:db()` will return all logical fields, including foreign key ids and composite DB Fields, alongside
any child fields of these composites. This method can now take a second parameter $includesTable, which
when set to true (with a field name as the first parameter), will also include the table prefix in
`Table.ClassName(args)` format.
Composite database fields are omitted from the `databaseFields()` method. To get those, use `DataObject::getSchema()->compositeFields($className, $aggregate = true)`.
### Rewrite SQLQuery to more specific classes {#sqlquery}