Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: Static validation for relationships. #9874

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/en/02_Developer_Guides/00_Model/02_Relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ class Company extends DataObject
```

Multiple `$has_one` relationships are okay if they aren't linking to the same object type. Otherwise, they have to be
named.
named. With that said, naming is recommended in all cases as it makes your code more resilient to change. Adding new relationships is easier when you don't need to review and update existing ones.

You can use `RelationValidationService` for validation of relationships. This tool will point out the relationships which may need a review.

If you're using the default scaffolded form fields with multiple `has_one` relationships, you will end up with a CMS field for each relation. If you don't want these you can remove them by their IDs:

Expand All @@ -224,6 +226,8 @@ declaring the `$belongs_to`.
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.

You can use `RelationValidationService` for validation of relationships. This tool will point out the relationships which may need a review.

```php
use SilverStripe\ORM\DataObject;

Expand Down Expand Up @@ -251,7 +255,7 @@ how the developer wishes to manage this join table.

[warning]
Please specify a $belongs_many_many-relationship on the related class as well, in order
to have the necessary accessors available on both ends.
to have the necessary accessors available on both ends. You can use `RelationValidationService` for validation of relationships. This tool will point out the relationships which may need a review.
emteknetnz marked this conversation as resolved.
Show resolved Hide resolved
[/warning]

Much like the `has_one` relationship, `many_many` can be navigated through the `ORM` as well.
Expand Down
Loading