Added FQCN for Image and File in use statements

Sorry, first pull request. I added the Image and File use statements as requested. And surrounded the has_many example with the class name so it makes more sense.
This commit is contained in:
blueskies79 2018-04-24 10:49:45 +02:00 committed by GitHub
parent 8b36a2ceae
commit 84ae5ba321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,10 +42,17 @@ and provides a short syntax for accessing the related object.
To create a has_one/has_many relationship to core classes (File, Image, etc), reference the Classname::class, like below.
```php
use SilverStripe\ORM\DataObject;
use SilverStripe\Assets\Image;
use SilverStripe\Assets\File;
class Team extends DataObject
{
private static $has_many = [
'Teamphoto' => Image::class,
'Lineup' => File::class
];
];
}
```
At the database level, the `has_one` creates a `TeamID` field on `Player`. A `has_many` field does not impose any database changes. It merely injects a new method into the class to access the related records (in this case, `Players()`)