Merge pull request #8017 from open-sausages/pulls/4/fix-broken-versioning-link

Fix a broken link to the versioning page
This commit is contained in:
Robbie Averill 2018-04-19 11:07:39 +12:00 committed by GitHub
commit 04bf73bff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,13 +12,13 @@ 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
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.
```php
use SilverStripe\ORM\DataObject;
class Team extends DataObject
class Team extends DataObject
{
private static $db = [
'Title' => 'Varchar'
@ -28,7 +28,7 @@ class Team extends DataObject
'Players' => 'Player'
];
}
class Player extends DataObject
class Player extends DataObject
{
private static $has_one = [
"Team" => "Team",
@ -75,13 +75,13 @@ Ideally, the associated has_many (or belongs_to) should be specified with dot no
```php
use SilverStripe\ORM\DataObject;
class Player extends DataObject
class Player extends DataObject
{
private static $has_many = [
"Fans" => "Fan.FanOf"
];
}
class Team extends DataObject
class Team extends DataObject
{
private static $has_many = [
"Fans" => "Fan.FanOf"
@ -89,7 +89,7 @@ class Team extends DataObject
}
// Type of object returned by $fan->FanOf() will vary
class Fan extends DataObject
class Fan extends DataObject
{
// Generates columns FanOfID and FanOfClass
@ -119,7 +119,7 @@ available on both ends.
```php
use SilverStripe\ORM\DataObject;
class Team extends DataObject
class Team extends DataObject
{
private static $db = [
'Title' => 'Varchar'
@ -129,7 +129,7 @@ class Team extends DataObject
'Players' => 'Player'
];
}
class Player extends DataObject
class Player extends DataObject
{
private static $has_one = [
@ -160,14 +160,14 @@ To specify multiple `$has_many` to the same object you can use dot notation to d
```php
use SilverStripe\ORM\DataObject;
class Person extends DataObject
class Person extends DataObject
{
private static $has_many = [
"Managing" => "Company.Manager",
"Cleaning" => "Company.Cleaner",
];
}
class Company extends DataObject
class Company extends DataObject
{
private static $has_one = [
"Manager" => "Person",
@ -192,27 +192,27 @@ public function getCMSFields()
## belongs_to
Defines a 1-to-1 relationship with another object, which declares the other end of the relationship with a
corresponding `$has_one`. A single database column named `<relationship-name>ID` will be created in the object with the
`$has_one`, but the $belongs_to by itself will not create a database field. This field will hold the ID of the object
Defines a 1-to-1 relationship with another object, which declares the other end of the relationship with a
corresponding `$has_one`. A single database column named `<relationship-name>ID` will be created in the object with the
`$has_one`, but the $belongs_to by itself will not create a database field. This field will hold the ID of the object
declaring the `$belongs_to`.
Similarly with `$has_many`, dot notation can be used to explicitly specify the `$has_one` which refers to this relation.
Similarly with `$has_many`, dot notation can be used to explicitly specify the `$has_one` which refers to this relation.
This is not mandatory unless the relationship would be otherwise ambiguous.
```php
use SilverStripe\ORM\DataObject;
class Team extends DataObject
class Team extends DataObject
{
private static $has_one = [
'Coach' => 'Coach'
];
}
class Coach extends DataObject
class Coach extends DataObject
{
private static $belongs_to = [
'Team' => 'Team.Coach'
];
@ -253,7 +253,7 @@ config to add extra columns.
```php
use SilverStripe\ORM\DataObject;
class Team extends DataObject
class Team extends DataObject
{
private static $many_many = [
"Supporters" => "Supporter",
@ -261,12 +261,12 @@ class Team extends DataObject
private static $many_many_extraFields = [
'Supporters' => [
'Ranking' => 'Int'
'Ranking' => 'Int'
]
];
}
class Supporter extends DataObject
class Supporter extends DataObject
{
private static $belongs_many_many = [
"Supports" => "Team",
@ -290,7 +290,7 @@ This is declared via array syntax, with the following keys on the many_many:
- `through` Class name of the mapping table
- `from` Name of the has_one relationship pointing back at the object declaring many_many
- `to` Name of the has_one relationship pointing to the object declaring belongs_many_many.
Note: The `through` class must not also be the name of any field or relation on the parent
or child record.
@ -299,7 +299,7 @@ The syntax for `belongs_many_many` is unchanged.
```php
use SilverStripe\ORM\DataObject;
class Team extends DataObject
class Team extends DataObject
{
private static $many_many = [
"Supporters" => [
@ -309,18 +309,18 @@ class Team extends DataObject
]
];
}
class Supporter extends DataObject
class Supporter extends DataObject
{
private static $belongs_many_many = [
"Supports" => "Team",
];
}
class TeamSupporter extends DataObject
class TeamSupporter extends DataObject
{
private static $db = [
'Ranking' => 'Int',
];
private static $has_one = [
'Team' => 'Team',
'Supporter' => 'Supporter',
@ -353,7 +353,7 @@ For instance, this is how you would link an arbitrary object to many_many tags.
```php
use SilverStripe\ORM\DataObject;
class SomeObject extends DataObject
class SomeObject extends DataObject
{
// This same many_many may also exist on other classes
private static $many_many = [
@ -364,13 +364,13 @@ class SomeObject extends DataObject
]
];
}
class Tag extends DataObject
class Tag extends DataObject
{
// has_many works, but belongs_many_many will not
private static $has_many = [
'TagMappings' => TagMapping::class,
];
/**
* Example iterator placeholder for belongs_many_many.
* This is a list of arbitrary types of objects
@ -382,9 +382,9 @@ class Tag extends DataObject
yield $mapping->Parent();
}
}
}
class TagMapping extends DataObject
class TagMapping extends DataObject
{
private static $has_one = [
'Parent' => DataObject::class, // Polymorphic has_one
@ -407,7 +407,7 @@ The joined record can be accessed via `Join` or `TeamSupporter` property (many_m
```
You can also use `$Join` in place of the join class alias (`$TeamSupporter`), if your template
is class-agnostic and doesn't know the type of the join table.
is class-agnostic and doesn't know the type of the join table.
## belongs_many_many
@ -421,16 +421,16 @@ distinguish them like below:
```php
use SilverStripe\ORM\DataObject;
class Category extends DataObject
class Category extends DataObject
{
private static $many_many = [
'Products' => 'Product',
'FeaturedProducts' => 'Product'
];
}
class Product extends DataObject
class Product extends DataObject
{
private static $belongs_many_many = [
'Categories' => 'Category.Products',
@ -471,7 +471,7 @@ are supported, as are methods that return lists of objects but do not correspond
If your object is versioned, cascade_deletes will also act as "cascade unpublish", such that any unpublish
on a parent object will trigger unpublish on the child, similarly to how `owns` causes triggered publishing.
See the [versioning docs](/developer_guides/versioning) for more information on ownership.
See the [versioning docs](/developer_guides/model/versioning) for more information on ownership.
## Cascading duplications
@ -514,7 +514,7 @@ $dupe = $parent->duplicate(true, false);
## Adding relations
Adding new items to a relations works the same, regardless if you're editing a **has_many** or a **many_many**. They are
Adding new items to a relations works the same, regardless if you're editing a **has_many** or a **many_many**. They are
encapsulated by [HasManyList](api:SilverStripe\ORM\HasManyList) and [ManyManyList](api:SilverStripe\ORM\ManyManyList), both of which provide very similar APIs, e.g. an `add()`
and `remove()` method.
@ -532,7 +532,7 @@ $team->Supporters()->add($supporter);
## Custom Relations
You can use the ORM to get a filtered result list without writing any SQL. For example, this snippet gets you the
You can use the ORM to get a filtered result list without writing any SQL. For example, this snippet gets you the
"Players"-relation on a team, but only containing active players.
See [DataObject::$has_many](api:SilverStripe\ORM\DataObject::$has_many) for more info on the described relations.
@ -540,13 +540,13 @@ See [DataObject::$has_many](api:SilverStripe\ORM\DataObject::$has_many) for more
```php
use SilverStripe\ORM\DataObject;
class Team extends DataObject
class Team extends DataObject
{
private static $has_many = [
"Players" => "Player"
];
public function ActivePlayers()
public function ActivePlayers()
{
return $this->Players()->filter('Status', 'Active');
}
@ -555,20 +555,20 @@ class Team extends DataObject
```
<div class="notice" markdown="1">
Adding new records to a filtered `RelationList` like in the example above doesn't automatically set the filtered
Adding new records to a filtered `RelationList` like in the example above doesn't automatically set the filtered
criteria on the added record.
</div>
## Relations on Unsaved Objects
You can also set *has_many* and *many_many* relations before the `DataObject` is saved. This behavior uses the
[UnsavedRelationList](api:SilverStripe\ORM\UnsavedRelationList) and converts it into the correct `RelationList` when saving the `DataObject` for the first
You can also set *has_many* and *many_many* relations before the `DataObject` is saved. This behavior uses the
[UnsavedRelationList](api:SilverStripe\ORM\UnsavedRelationList) and converts it into the correct `RelationList` when saving the `DataObject` for the first
time.
This unsaved lists will also recursively save any unsaved objects that they contain.
As these lists are not backed by the database, most of the filtering methods on `DataList` cannot be used on a list of
this type. As such, an `UnsavedRelationList` should only be used for setting a relation before saving an object, not
As these lists are not backed by the database, most of the filtering methods on `DataList` cannot be used on a list of
this type. As such, an `UnsavedRelationList` should only be used for setting a relation before saving an object, not
for displaying the objects contained in the relation.
## Related Lessons