Merge pull request #8333 from pine3ree/patch-3

$has_one docs
This commit is contained in:
Robbie Averill 2018-08-19 13:42:00 +12:00 committed by GitHub
commit 4f4df135d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -12,12 +12,18 @@ SilverStripe supports a number of relationship types and each relationship type
## has_one
A 1-to-1 relation creates a database-column called "`<relationship-name>`ID", in the example below this would be
"TeamID" on the "Player"-table.
Many-to-1 and 1-to-1 relationships create a database-column called "`<relationship-name>`ID", in the example below this would be "TeamID" on the "Player"-table.
```php
use SilverStripe\ORM\DataObject;
class Player extends DataObject
{
private static $has_one = [
"Team" => "Team",
];
}
class Team extends DataObject
{
private static $db = [
@ -28,12 +34,6 @@ class Team extends DataObject
'Players' => 'Player'
];
}
class Player extends DataObject
{
private static $has_one = [
"Team" => "Team",
];
}
```
This defines a relationship called `Team` which links to a `Team` class. The `ORM` handles navigating the relationship