mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
commit
4f4df135d1
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user