DOCS Adjust owns upgrading example

Fixes #7598
This commit is contained in:
Damian Mooyman 2017-11-16 11:38:26 +13:00
parent e78fe401e6
commit 58b43f29a9
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A

View File

@ -1350,18 +1350,26 @@ These methods are deprecated:
### New Ownership API {#ownership}
In order to support the recursive publishing of dataobjects, a new API has been developed to allow
developers to declare dependencies between objects. This is done to ensure that the published state
of linked components are consistent with their "owner." Without the concept of ownership, these linked
components could be implicitly exposed on the frontend, which may not align with the intent of the
content author.
developers to declare dependencies between versioned objects.
For instance, on a products page which has a list of products, the products should not be published unless the products page is, too. The ownership API solves this by allowing you to declare
a two-way relationship between objects, typically, but not necessarily, linked by a database relationship
(`has_many`, `many_many`, etc.).
```php
private static $owns = [
'Banners', // This page depends on banners, declared as a separate 'has_mane'
'FooterImage', // This page depends on the footer image, declared as a separate 'has_one'
];
```
This is done to ensure that the published state of linked components are consistent with their "owner."
Without the concept of ownership, these linked components could be implicitly exposed on the frontend,
which may not align with the intent of the content author.
For instance, on a products page which has a list of products, the products should not be published unless
the products page is, too. The ownership API solves this by allowing you to declare a two-way relationship
between objects, typically, but not necessarily, linked by a database relationship
(`has_many`, `many_many`, etc.).
```php
use SilverStripe\Versioned\Versioned;
use Page;
use SilverStripe\ORM\DataObject;
class ProductPage extends Page
@ -1386,6 +1394,7 @@ class Product extends DataObject
];
}
```
If your objects are linked by something other than a database relationship, for instance, a custom
getter that is computed at runtime, the same rules can be applied, as long as you provide an `$owned_by`
setting on the child object.