Merge branch pull request #7604 from open-sausages/pulls/4.0/owns-example-upgrading

DOCS Adjust owns upgrading example
Fixes #7598
This commit is contained in:
Daniel Hensby 2017-11-16 10:53:38 +00:00
commit 4d1e659fed
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E

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_many'
'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.